Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to query the top 50% data in mysql

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is about how to query the top 50% of data in mysql. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Experimental environment:

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

The number of c equals 10, 7, and 9 is 11, more than half of them.

More than half of the item information.

General way, do not rely on the specific database.

Select t5. Recall journal t6. If null (round (t5. Sumtotalpact t6. Total2), 0) result from (

Select t3.rn ifnull t3.totalist t3.c ifnull (t4.total.0))

Select

T1.*

(

Select count (case when t2.total > t1.total then 1 when t2.total=t1.total and t2.ct1.total then 1 when t2.total=t1.total and t2.c t4.rn)

Group by t3.rn,t3.total,t3.c

) T5

Left join (

Select count (*) total from t

) T6 on (1x 1)

Where ifnull (round (t5.sumtotalswap t6.totaltal2), 0)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report