我有一个mysql查询,列出了标题,艺术家的数量
SELECT count(Key) AS Ocount, artist, title,domain, DATE_FORMAT(`FE`,'%m') AS eMonth
FROM gr
WHERE domain = 'site.com'
GROUP BY title
ORDER BY eMonth,Ocount Desc
第一个结果是
'195', 'akon', 'beautiful', 'site.com', '01'
'20', 'ludacris', 'intro', 'site.com', '01'
'11', 'don omar', 'taboo', 'site.com', '01'
运行与
相同的查询SELECT count(Key) AS Ocount, artist, title,domain, DATE_FORMAT(`FE`,'%m') AS eMonth
FROM gr
WHERE domain = 'site.com'
AND artist = 'akon'
AND title = 'beautiful'
结果
'100', 'akon', 'beautiful', 'site.com', '01'
这怎么可能?无论我怎么算,它都不能给出相同的结果吗?
答案 0 :(得分:1)
如果您想要每个标题 - 艺术家组合的计数,您将需要使用
GROUP BY artist, title
这将count(id)
表示该表中存在艺术家+标题组合的实例数。您可以使用WHERE
子句在计算COUNT()
之前过滤结果。
您可以从一小部分数据开始检查结果是否准确,并检查COUNT()
的结果是否准确。
仅按艺术家分组将导致与该艺术家匹配的行数,而不考虑标题。