简体   繁体   English

Oracle SQL:比较行数据总和与一列

[英]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#. 我有以下数据类型,对于特定的ID#,interval_mins的总和应该等于Total_mins。 I need the rows where it is missing a row for Interval_mins eg for ID# 20. How can I do that? 我需要缺少Interval_mins行的行,例如ID#20。我该怎么做? 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

If you are just looking for ids were the totals do not match: 如果您只是在寻找ID是否与总数不符:

select id
from t
group by id
having max(total_mins) <> sum(interval_mins);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM