我有一张 table ,例如
Artist Title Song Key
A Title A A
A Title A B
A Title A F
B Title B A
我想返回每首歌曲,但也显示该歌曲有多少个版本,例如理想的结果是:
Artist Title How_many
A Title A 3
B Title B 1
这就是我正在尝试的,但计数计算所有轨道,而不仅仅是当前行:
SELECT *,
( select count(*)
from tracks
where artist=artist
AND title=title ) as How_many
from tracks
where easytosing='Yes'
group by title, artist
order by track_id desc
使用嵌套查询可以实现这一点吗?或者有更好的方法吗?
最佳答案
试试这个:
SELECT Artist, title, count(*) as How_many
FROM tracks
WHERE easytosing='Yes'
GROUP BY Artist,Title
关于php - 基于结果的选择中选择 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18567574/