简体   繁体   中英

how to get top 5 for each category

I am using mysql. I have one table called flow_data There is two attributes category and views. category is int type and views is int type. category has 0-4(for example num 0 is video and num 1 is pics) and numbers of view is based on how many times users click. I want to query data that top5 views for each category.

SELECT DISTINCT id, cat, title, file, type, tags
FROM flow_data 
ORDER BY views 
LIMIT 5

It only returns top5 views not based on each category.

Any thought? Thank you advance.

There is rank query in oracle and sql server you may search for rank equivalent in mysql. You may see here . You may also see this and this also

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