Reputation: 3
I have a table like this:
What I would like to be able to do is return the IDs and how many different types of fruit the ID is associated with other than 1 like so:
Can someone help me out? I don't think it should be that difficult, but I haven't had much luck.
Thanks!
Upvotes: 0
Views: 216
Reputation: 1269493
I think you want the having
clause and count(distinct)
:
select id, count(distinct fruit) as numfruit
from t
group by id
having count(distinct fruit) > 1;
Upvotes: 1