SQL for total count and count within that where condition is true
Posted
by twmulloy
on Stack Overflow
See other posts from Stack Overflow
or by twmulloy
Published on 2010-05-16T06:30:41Z
Indexed on
2010/05/16
6:40 UTC
Read the original article
Hit count: 239
Hello, I have a single user table and I'm trying to come up with a query that returns the total count of all users grouped by date along with the total count of users grouped by date who are of a specific client.
Here is what I have thus far, where there's the total count of users grouped by date, but can't seem to figure out how to get the count of those users where user.client_id = x
SELECT user.created,
COUNT(user.id) AS overall_count
FROM user
GROUP BY DATE(user.created)
trying for a row result like this:
[created] => 2010-05-15 19:59:30
[overall_count] => 10
[client_count] => (some fraction of overall count, the number of users where
user.client_id = x grouped by date)
© Stack Overflow or respective owner