在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

mysql中如何查询前50%的数据

101次阅读
没有评论

共计 1414 个字符,预计需要花费 4 分钟才能阅读完成。

这篇文章给大家分享的是有关 mysql 中如何查询前 50% 的数据的内容。丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,一起跟随丸趣 TV 小编过来看看吧。

实验环境:

create table t (c int);
insert into t values 
(15),(7),(9),(10),(7),(8),(20),(16),(9),(19),
(14),(10),(11),(10),(10),(12),(7),(10),(7),(9);
commit; 

c 等于 10,7,9 的数量有   11 个,超过了半数。
超过半数的 item 信息。

通用方式, 不依赖具体数据库。

select t5.*,t6.*,ifnull(round(t5.sumtotal/t6.total,2),0) result from (

 select t3.rn,t3.total,t3.c,sum(ifnull(t4.total,0)) sumtotal from (

 select

 t1.*,

 (

 select count(case when t2.total t1.total then 1 when t2.total=t1.total and t2.c t1.c then 1 else null end)+1 from (

 select c,count(*) total from t group by c

 ) t2

 ) rn

 from(

 select c,count(*) total from t group by c order by total desc ,c

 ) t1

 ) t3

 left join(

 select

 t1.*,

 (

 select count(case when t2.total t1.total then 1 when t2.total=t1.total and t2.c t1.c then 1 else null end)+1 from (

 select c,count(*) total from t group by c

 ) t2

 ) rn

 from(

 select c,count(*) total from t group by c order by total desc ,c

 ) t1

 ) t4 on (t3.rn t4.rn)

 group by t3.rn,t3.total,t3.c

) t5

left join(

 select count(*) total from t

) t6 on(1=1)

where ifnull(round(t5.sumtotal/t6.total,2),0) =0.5;

查询结果:

绑定 MySQL 的实现

select * from (

 select t3.*,case when result =0.5 then 1 when result 0.5 and @b=-1 then @b:=1 else null end r from (

 select t1.*,round((@a:=@a+t1.total)/t2.total,2) result from (

 select c,count(*) total from t,(select @a:=0,@b:=-1) vars group by c order by 2 desc

 ) t1

 left join(

 select count(*) total from t

 ) t2 on(1=1)

 ) t3 order by result

) t4 where r=1;

结果:

感谢各位的阅读!关于“mysql 中如何查询前 50% 的数据”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-27发表,共计1414字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 青草内射中出高潮 | 日韩欧美二区 | 欧美成人午夜精品久久久 | 亚洲色婷婷六月亚洲婷婷6月 | 国产精品视频一区二区三区经 | 色综合久久久无码中文字幕 | 国产亚洲精品久久久久婷婷瑜伽 | 五月四色 | a毛片基地| 色人久久| 538prom国产在线视频一区 | 国产一浮力影院 | 国产成人精品免费视频大全办公室 | 在线看小视频 | 日本久久精品免视看国产成人 | 国产日本欧美高清免费区 | 国产手机精品一区二区 | 毛片无码免费无码播放 | 884hutv四虎永久7777 | 亚洲久久影院 | 深夜激情网站 | 欧美一区二区三区四区五区六区 | 精品手机在线 | 久久国产亚洲偷自 | 久久婷婷大香萑太香蕉av人 | 亚洲av午夜福利精品一区 | 色老成人精品视频在线观看 | 国产精品va在线播放我和闺蜜 | 最近中文字幕视频在线资源 | 中文字幕 亚洲 一区二区三区 | 18成人免费观看软件大全 | 国产亚洲精品久久久久秋 | 国产成人精品亚洲2020 | 宅男午夜视频在线观看 | 国产小视频网站 | 欧美日韩国产一区二区三区 | 午夜精| a毛片在线还看免费网站 | 色狠狠色噜噜av天堂一区 | aaa黄色大片 | 亚洲国产精品久久人人爱 |