Kaur Kaur - 2 years ago 94
SQL Question

Oracle SQL : comparing sum of rows data to one column

I have following type of data, where sum of interval_mins is supposed to be equal to Total_mins for a particular ID#. I need the rows where it is missing a row for Interval_mins e.g. for ID# 20. How can I do that? Thanks,

ID Date Interval_mins Total_mins
10 4/1/16 60 80
10 4/1/16 20 80
20 4/1/16 60 85

Answer Source

If you are just looking for ids were the totals do not match:

select id
from t
group by id
having max(total_mins) <> sum(interval_mins);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download