0

我需要按艺术家计算标题

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

我究竟做错了什么?

4

1 回答 1

1

你不应该选择不在你的列GROUP BY,即使 MySQL 扩展了它。

SELECT artist, title, 
    COUNT(*) AS countTitles 
FROM table 
WHERE domain = 'domain.com' 
GROUP BY artist, title
ORDER BY countTitles DESC;
于 2012-11-08T19:22:54.693 回答