I have a query which counts records with duplicate titles (> 1) but I want it only to include results where status
column is distinct. For example, if two videos have same title and same status (ie. status=2 for both), it should only be counted once. If there are 3 videos with two of the records containing the same status, the count should be 2.
This is my query so far...
SELECT COUNT(*) AS `count`,`title` FROM `videos` GROUP BY `title` HAVING `count`>1;
Use count
with distinct
instead:
SELECT COUNT(distinct status) AS `count`,`title`
FROM `videos`
GROUP BY `title`
HAVING `count`>1;
尝试...
SELECT COUNT(DISTINCT status) AS `count`,`title` FROM `videos` GROUP BY `title` HAVING `count`>1;
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.