2

我正在使用以下查询返回多次出现在表格中的艺术家的姓名,并且第一个字符以 A 开头

SELECT DISTINCT artist FROM releases WHERE artist LIKE 'a%' ORDER BY artist

我现在想更进一步,只想返回出现超过 10 次的艺术家

我该怎么做?

干杯!

4

3 回答 3

3

最好的方法是使用 aGROUP BY来获取艺术家出现的次数,然后使用HAVING来指示他们至少需要出现一定次数。

我相信这个查询会给你你想要的:

SELECT artist, count(*) 
FROM releases 
WHERE artist LIKE 'a%'
GROUP BY artist 
ORDER BY artist
HAVING count(*) > 10
于 2012-06-16T04:19:48.130 回答
1
SELECT artist, count(*)  FROM releases 
WHERE artist LIKE 'a%' GROUP BY artist
ORDER BY artist
HAVING count(*) > 10 
于 2012-06-16T04:28:50.267 回答
0

您的查询选择只有艺术家姓名:

select artist from releases
where artist like 'a%' group by artist 
having count(distinct(artist))>10;
于 2012-06-16T04:27:48.433 回答