一個不錯的查詢語句
2012-1-30 11:23 Monday  

分类: MySQL 评论(58) 浏览(48031)

可以查詢某個字段在數據庫中出現最多的前N項

SELECT TOP N author,ct=count(author)
FROM YourTableName
GROUP BY author
ORDER BY ct DESC

但是在MYSQL5.0以後,好像不能用,改成這樣就能用了

SELECT author,count(author) as ct
FROM YourTableName
GROUP BY author
ORDER BY ct DESC LIMIT N

+1 24

留下你的看法: