I have data in table like below:
Primary_id Serial_ID PRIMARY_ID SECONDARY_ID queue_ID
1 100 58 89 Q1428291
2 100 58 89 Q1428281
3 100 58 89 Q1428293
4 100 89 58 Q1428293
5 100 89 58 Q1428291
6 100 89 58 Q1428000281
7 200 16 28 Q1433144
8 200 16 28 Q1431953
9 200 16 28 Q1432397
10 200 16 28 Q1431921
11 200 28 16 Q1433144
12 200 28 16 Q1432397
13 200 28 16 Q1431921
We have primary_ID and Secondary_ID column. for serial_ID 100 we have 3 primary and 3 secondary records..If you see the data Primary_ID become secondary and secondary become primary(3 each).but for serial_id 200 we have 4 primary records but 3 secondar records..
I want such records which have these kind of mismatch. Please assist
If I understand correctly, you want the same number of rows for each primary/secondary combination on a serial_id
. If that is correct, you can use two levels of aggregation:
select serial_id
from (select serial_id, primary_id, secondary_id, count(*) as cnt
from t
group by serial_id, primary_id, secondary_id
) ps
group by serial_id
having min(cnt) <> max(cnt);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.