Mysql仅选择行的百分比 [英] Mysql Select only percentage of rows

查看:75
本文介绍了Mysql仅选择行的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用第二列(art_count)仅显示那些包含总art_count的X%的行.

I want to use the second column (art_count) to show only those rows containing X percent of total art_count.

我的数据:

title   art_count
a       3
b       12
c       9
d       4
e       45

到目前为止,我的查询是

My query so far:

SELECT title, COUNT(art) AS art_count
FROM table1
GROUP BY art HAVING ... ?

使用SUM进行了尝试,但未成功.

Tried it with SUM without success.

推荐答案

SELECT title, COUNT(art) AS art_count
FROM table1
GROUP BY art 
HAVING art_count >= (select count(*) * X / 100 from table1)

您需要为X

这篇关于Mysql仅选择行的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆