I am trying to check whether the output for a specific account number and for the different organizations is the same and show the discrepancies in Oracle
Imagine i have a table called myTable and it contains 2 fields: accountnumber and org_id
There exist only 3 org_id: 81, 281 and 404
Dataset:
|accountnumber|org_id|
|4435354 |81 |
|4435354 |281 |
|4435354 |404 |
|3333333 |81 |
|3333333 |281 |
|4444444 |81 |
|4444444 |81 |
|4444444 |281 |
|4444444 |404 |
I want to find all the different accounts that dont have the exact amount for each org_id
For example:
account 4435354 has 1 row for org_id 81, 1 row for org_281 and 1 row for org_id 404, so in this case it is correct
account 3333333 has 1 row for org_id 81, 1 row for org_281 and none for 404 so there exist a discrepancy
account 4444444 has 2 rows for org_id 81, 1 row for org_281 and 1 row for org_id 404, so there exist a discrepancy
DESIRED OUTPUT:
ACCOUNTNUMBER| ORG_ID|COUNT(*)
|3333333 | 81 |1
|3333333 | 281 |1
|3333333 | 404 |0
|4444444 | 81 |2
|4444444 | 281 |1
|4444444 | 404 |1
How can i achieve something like that in Oracle?
EDIT #1
This scenario is a valid one and should not be displayed
|9999999 |81 |
|9999999 |81 |
|9999999 |81 |
|9999999 |404 |
|9999999 |404 |
|9999999 |404 |
|9999999 |281 |
|9999999 |281 |
|9999999 |281 |
It is correct because every org_id for that accountnumber has 3 in each one and it is correct
