Reputation: 2672
I am new to SQL so don't know much about it. Please help. I have a database something like this:
User Model
A X
A X
A X
B Y
C Y
C Y
D X
D X
E Z....
I want to calculate the frequency of the each unique model respective to unique users. I mean the output should be something like this:
Model Count
X 2
Y 2
Z 1
as A and D use model X, so X=2. Similarly B and C use model Y, so Y=2. and same goes for Z(only user E). How do I achieve this?
Upvotes: 0
Views: 46
Reputation: 49260
Use group by
.
select model,count(distinct user)
from tbl
group by model
Upvotes: 4