Reputation: 49
I want to find all statuses such that the value is always NO
. THAT MEANS I WANT OUTPUT IS 2 ONLY BECAUSE ITS ALL VALUE IS NO.
HOW I GET THE VALUE THROUGH SQL QUERY
STATUS_ID STATUS
1 YES
1 YES
2 NO
2 NO
2 NO
3 YES
3 NO
Upvotes: 0
Views: 121
Reputation: 520968
Just do a basic conditional aggregation:
SELECT STATUS_ID
FROM yourTable
GROUP BY STATUS_ID
HAVING SUM(CASE WHEN STATUS <> 'NO' THEN 1 ELSE 0 END) = 0;
Upvotes: 3