我正在使用以下查询返回多次出现在表格中的艺术家的姓名,并且第一个字符以 A 开头
SELECT DISTINCT artist FROM releases WHERE artist LIKE 'a%' ORDER BY artist
我现在想更进一步,只想返回出现超过 10 次的艺术家
我该怎么做?
干杯!
我正在使用以下查询返回多次出现在表格中的艺术家的姓名,并且第一个字符以 A 开头
SELECT DISTINCT artist FROM releases WHERE artist LIKE 'a%' ORDER BY artist
我现在想更进一步,只想返回出现超过 10 次的艺术家
我该怎么做?
干杯!
最好的方法是使用 aGROUP BY
来获取艺术家出现的次数,然后使用HAVING
来指示他们至少需要出现一定次数。
我相信这个查询会给你你想要的:
SELECT artist, count(*)
FROM releases
WHERE artist LIKE 'a%'
GROUP BY artist
ORDER BY artist
HAVING count(*) > 10
SELECT artist, count(*) FROM releases
WHERE artist LIKE 'a%' GROUP BY artist
ORDER BY artist
HAVING count(*) > 10
您的查询选择只有艺术家姓名:
select artist from releases
where artist like 'a%' group by artist
having count(distinct(artist))>10;