我需要按艺术家来计算头衔

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


我究竟做错了什么?

最佳答案

即使MySQL对此进行了扩展,也不应选择不在GROUP BY中的列。

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

关于mysql - mysql-计数问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13296167/

10-10 23:20