Reputation: 111
So I have and email data base and where each email send has it's own line. I'm trying to figure out how many times each user is being sent to. So I'm using this query to find out out how many times each user has been mailed.
SELECT count(`id`)
FROM `bde_export`
WHERE `record.type` = 'senttomta'
GROUP BY `user.id`
Now what I'm trying to do is count that count so I get a summary telling me how many users have been mailed 1,2,3,4 times and so on. I know that is a bit confusing please let me know if clarification is needed.
Upvotes: 0
Views: 38
Reputation: 388
You can do this with two selection statements.. try something like this..
SELECT SUM(s.EmailCount) as 'TotalCount', s.id
FROM
(
SELECT COUNT(id) as 'EmailCount', id
FROM
GROUP BY user.id
) AS s
GROUP BY s.EmailCount
Basically you do your initial select statement and select the sum of the initial count
Upvotes: 0
Reputation: 310
well why dont you try another count??? like this
SELECT count(`tmp`.*) FROM (
SELECT count(`id`)
FROM `bde_export`
WHERE `record`.`type` = 'senttomta'
GROUP BY `user`.`id`
) `tmp`
i dont know what exactly is your problem but with current explanation i think it works. i just copied your query and didnt change that.
but if it doesn't satisfy your meets, i suggest you to try this:
SELECT sum(`tmp`.`count`) FROM (
SELECT count(`id`) AS `count`
FROM `bde_export`
WHERE `record`.`type` = 'senttomta'
GROUP BY `user`.`id`
) `tmp`
Upvotes: 1