0

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?

1 Answer 1

4

Use group by.

select model,count(distinct user)
from tbl
group by model
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.