我想使用第二列(art_count)仅显示包含总art_count的X%的行。
我的数据:
title art_count
a 3
b 12
c 9
d 4
e 45
到目前为止我的查询:
SELECT title, COUNT(art) AS art_count
FROM table1
GROUP BY art HAVING ... ?
用SUM尝试但没有成功。
答案 0 :(得分:5)
SELECT title, COUNT(art) AS art_count
FROM table1
GROUP BY art
HAVING art_count >= (select count(*) * X / 100 from table1)
您需要为X