oracle 分组之后求和并过滤
select prodSeqNo, placeNo, sum(replaceTimes)
from (select * from xxx where prodSeqNo in ('xxx','xxx','vvv')) temp
where xxx='xxx' and yyy='yyy'
group by prodSeqNo, placeNo
having sum(replaceTimes) >= 2
order by placeNo;
PS:
1、上面的sql大意:查询同一个prodSeqNo下的同一个placeNo的replaceTimes(更换次数)大于等于2的记录;
2、select中的字段必须出现在group by 中(聚合函数除外);having用于对分组之后的结果进行过滤;order by用于group by 之后。