SQLite选择专辑的数量

时间:2014-10-31 10:05:58

标签: sql sqlite

我想选择具有相册数量的唯一艺术家。

在MusicLibrary表格中,会保存各首歌曲。 (标题,艺术家,专辑......)

我试过了:

SELECT distinct artist, album, Count(*) from MusicLibrary group by artist order by artist

但是我得到了歌曲的数量。

如果有人能帮助我,我将非常感激

2 个答案:

答案 0 :(得分:2)

由于您保存该表格中的每首歌曲,因此您需要在计数中使用distinct来计算唯一的专辑,而不是每位艺术家的歌曲数量

SELECT artist, Count(distinct album) as albums
from MusicLibrary 
group by artist 
order by artist 

答案 1 :(得分:-1)

SELECT artist, Count(album)
from MusicLibrary
group by artist
order by artist