Reputation: 11
First post here... :)
What I have is this:
Client / Model
And what I need to show is:
Model / Total
1 / 3
The code I have is:
SELECT Client, Model, COUNT(Model) Total
FROM Table
GROUP BY Client, Model
but all this does is return every occurrence of both columns. Can anyone help, please?
Thank you in advance.
Upvotes: 1
Views: 759
Reputation: 9618
It looks like you want the number of "clients" for each model; so try this:
select model
, count(distinct client) as Total
from table
group by model
Upvotes: 1
Reputation: 238076
To count the number of distinct clients per model:
SELECT Model
, COUNT(distinct Client) Total
FROM Table
GROUP BY
Model
Upvotes: 5
Reputation: 1605
This is due by the Client in the group by. Exclude the Client from your query. Try this :
SELECT Model, COUNT(Model) Total
FROM Table
GROUP BY MODEL
Upvotes: 1