count query filter
I want to filter counted query result.
select count(d开发者_Go百科istinct tmr_id) AS Count ,CONTRACTID from status_handling
This query return 2 columns like:
Count ContractID
1 23344
2 28344
2 34343
2 29344
1 26344
I just filter 2 (Count) values. How can I do this?
Thanks.
In Oracle we have to use GROUP BY with aggregate functions. When we want to filter by the aggregated result there is the HAVING clause:
select count(distinct tmr_id) ,CONTRACT_ID
from status_handling
group by CONTRACT_ID
having count(distinct tmr_id) = 2
/
精彩评论