I would like to get all lines, which have different entries to fields anln1 and anln2. For this I need a fitting OpenSQL statement.
E.g. there is the following table:
anln1 | anln2 | datum | psp | przt
------------------------------------------
10007 | 0 | 20140101 | 12345678 | 1
10007 | 0 | 20140101 | 11111111 | 99
10007 | 1 | 20140101 | 12345678 | 1
10007 | 1 | 20140101 | 11111111 | 99
All entries for anln1 + anln2 should repeat their combination of datum, psp and przt if there is another subnumber, e.g. anln2=1.
Unfortunately my table has breaches to this specification (SQLFiddle: http://sqlfiddle.com/#!2/f5d1f):
anln1 | anln2 | datum | psp | przt
------------------------------------------
10000 | 0 | 20140101 | 12345678 | 60
10000 | 0 | 20140101 | 11111111 | 40
10000 | 1 | 20140101 | 11111111 | 100
10000 | 2 | 20140101 | 11111111 | 100
10000 | 3 | 20140101 | 22222222 | 100
10001 | 0 | 20140101 | 12312312 | 100
10001 | 1 | 20140101 | 12312312 | 100
10001 | 2 | 20140101 | 12312312 | 100
10002 | 0 | 20140101 | 11111111 | 100
10003 | 0 | 20140101 | 11111111 | 100
10004 | 0 | 20140101 | 11111111 | 100
10005 | 0 | 20140101 | 22222222 | 100
10005 | 1 | 20140101 | 33333333 | 100
10006 | 0 | 20140101 | 11111111 | 20
10006 | 0 | 20140101 | 22222222 | 80
10006 | 1 | 20140101 | 11111111 | 30
10006 | 1 | 20140101 | 11111111 | 70
10007 | 0 | 20140101 | 12345678 | 1
10007 | 0 | 20140101 | 11111111 | 99
10007 | 1 | 20140101 | 12345678 | 1
10007 | 1 | 20140101 | 11111111 | 99
As a result to my query I need all the lines identified, where my specification is breached. The correct lines should be just left out. Correct lines are the ones where anln1 is 10001, 10002, 10003, 10004, 10007.
So, the result should look like this:
anln1 | anln2 | datum | psp | przt
------------------------------------------
10000 | 0 | 20140101 | 12345678 | 60
10000 | 0 | 20140101 | 11111111 | 40
10000 | 1 | 20140101 | 11111111 | 100
10000 | 2 | 20140101 | 11111111 | 100
10000 | 3 | 20140101 | 22222222 | 100
10005 | 0 | 20140101 | 22222222 | 100
10005 | 1 | 20140101 | 33333333 | 100
10006 | 0 | 20140101 | 11111111 | 20
10006 | 0 | 20140101 | 22222222 | 80
10006 | 1 | 20140101 | 11111111 | 30
10006 | 1 | 20140101 | 11111111 | 70
I tried things with GROUP BY, HAVING and COUNT(...) > 1, but I didn't get to a useful result. Is this even solvable with (Open)SQL?
Really looking forward to your help! Please use my SQLFiddle (http://sqlfiddle.com/#!2/f5d1f) to try around.