我有一个查询来计算具有重复标题的记录(> 1),但我希望它只包含status
列不同的结果。例如,如果两个视频具有相同的标题和相同的状态(即两者的状态= 2),则只应计算一次。如果有3个视频,其中两个记录包含相同的状态,则计数应为2。
这是我目前的询问......
SELECT COUNT(*) AS `count`,`title` FROM `videos` GROUP BY `title` HAVING `count`>1;
答案 0 :(得分:0)
使用count
代替distinct
:
SELECT COUNT(distinct status) AS `count`,`title`
FROM `videos`
GROUP BY `title`
HAVING `count`>1;
答案 1 :(得分:-1)
试试......
SELECT COUNT(DISTINCT status) AS `count`,`title` FROM `videos` GROUP BY `title` HAVING `count`>1;