简体   繁体   English

mySQL选择热门下载热门用户

[英]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. 我尝试了SUM方法,但只显示了前一个用户。 Is there any solution for this query ? 这个查询有什么解决方案吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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