I'm trying to create one query to select some data. I need to select them only as DISTINCT but count each group of items inside each container eg
results: CATEGORY EMAIL
what I need: Jo1 3 -> count unique users Jo2 2 -> count unique users
I can do it with distinct to split them but can't find a way of counting separate groups. SELECT count(DISTINCT CATEGORY)
... counting all users.
Thnanks,
You should be COUNT(DISTINCT)
ing email
not category
:
SELECT `CATEGORY`, COUNT(DISTINCT `EMAIL`)
FROM the_table
GROUP BY `CATEGORY`
;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.