简体   繁体   中英

check all data, count them, sort by count and return one of each data bt mysql

I have a table that contains some data like below:

Id : 1,2,3,4,5,6,7,8,9,10

data : 3,2,3,2,5,3,2,3,5,1

And I want this output: 3,2,5,1

This means that MySQL check all data, count them, sort by count and return one of each data.

I try @mysql_query ('SELECT * FROM datatable GROUP BY data');

But it returns an unsorted group data and I have repeated data like 3333222551

Note: I included data in the ORDER BY clause so that you get a deterministic order in case of a tie in counts:

SELECT `data`
FROM `datatable` 
GROUP BY `data`
ORDER BY COUNT(*) DESC, `data`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM