views:

17

answers:

1

I want to filter counted query result.

select count(distinct 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.

+5  A: 

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
/
APC
thanks! .......
Jack