Not sure if this question is duplicated yet or not.
I have a simplified table below
User | Interest |
---|---|
Jason | Art |
Jason | Sport |
Sam | Sport |
Sam | Art |
Steve | Sport |
Desmond | Sport |
Tania | Art |
Here's the result that I want to achieve
Interest | Count |
---|---|
Art | 2 |
Sport | 2 |
Both | 2 |
I Managed to make a subquery to achieve the value for the Both
data by this query
SELECT COUNT(USER) FROM (
SELECT User, COUNT(DISTINCT Interest) as interest_type FROM table WHERE interest_type = 2)
But for the user that are exclusively have Interest
in Art
and in Sport
it's not separated.