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