mysql - 计数问题

时间:2012-11-08 19:20:15

标签: mysql

我需要按艺术家计算标题

SELECT artist,
    title,
    label,
    COUNT(title) AS countTitles 
FROM table 
WHERE domain = 'domain.com' 
GROUP BY title 
ORDER BY countTitles DESC;

但结果只让我获得了标题的统计 - 与不同的艺术家合作。

我想:

artist1 - title1a
artist1 - title2a
artist1 - title1a
artist1 - title1a
artist1 - title1a

我想像这样计算

artist1 - title1a - 4
artist1 - title2a - 1

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您不应选择不在GROUP BY中的列,即使MySQL扩展了这一列。

SELECT artist, title, 
    COUNT(*) AS countTitles 
FROM table 
WHERE domain = 'domain.com' 
GROUP BY artist, title
ORDER BY countTitles DESC;