简体   繁体   中英

mySQL select top user with top download hits

Let's say I have a table that stores user info with each row structured like:

(int) FileId |(int) userId | (int) DownloadHits | (varchar) UserName

Each user may have a lots of files uploaded by their names. I want to show a list of user that have top download hits, look like :

userId    UserName     DownloadHits
  1          Key             120  
  2          Bob             50  
  3          Zero            15  

I tried SUM method but it only show the top one user. Is there any solution for this query ?

select userid,username,
sum(downloadhits) as theDowns
from tblName
group by userid,username
order by theDowns desc

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