ID fileName userName
1 abc1 Emre
2 abc2 Abc
3 abc2 John
4 abc1 Rick
5 abc1 Rick
絲網印刷: Mysql;數據總
頂部下載的文件: 1) ABC1 2) ABC2
我想展現的淋漓盡致下載的文件。我怎樣才能做一個MySQL查詢?
(對不起,英)
ID fileName userName
1 abc1 Emre
2 abc2 Abc
3 abc2 John
4 abc1 Rick
5 abc1 Rick
絲網印刷: Mysql;數據總
頂部下載的文件: 1) ABC1 2) ABC2
我想展現的淋漓盡致下載的文件。我怎樣才能做一個MySQL查詢?
(對不起,英)
獲得的聚集體通過COUNT()
fileName
分組。按下載次數降序排列,並根據您想返回的結果數量進行限制(如有必要)。
SELECT
fileName,
COUNT(*) AS downloads
FROM yourtable
GROUP BY fileName
ORDER BY downloads DESC
/* Optionally limit the number returned */
LIMIT 2;
SELECT fileName, COUNT(*) AS DownloadCount
FROM YourTable
GROUP BY fileName
ORDER BY DownloadCount DESC;
您可以通過在fileName
select fileName, count(1) as qty_dl
from your_table
group by fileName
order by qty_dl desc
SELECT `fileName`, COUNT(`fileName`) AS `count`
FROM `tableName`
GROUP BY `fileName`
ORDER BY `count` DESC
LIMIT 2;
一個`FROM`條款分組可能會有所幫助使用
COUNT
聚合函數。 :-) – 2011-12-15 15:26:09@JoeStefanelli的確... – 2011-12-15 15:29:07
感謝您的關注! – Editor 2011-12-15 15:45:33