返回具有最大值的单行

时间:2011-07-31 10:35:53

标签: mysql

我有一个包含某些字段的表格(trackid,artist,countview),我只需要返回最大countview值的行。

尝试

SELECT trackid, artist, MAX(countview) FROM tracklist

但我觉得我应该穿上HAVING?

5 个答案:

答案 0 :(得分:2)

SELECT trackid, artist, countview
FROM tracklist 
ORDER BY countview DESC LIMIT 1

答案 1 :(得分:1)

SELECT trackid,artist FROM tracklist WHERE countview =(SELECT MAX(countview)FROM tracklist)

答案 2 :(得分:1)

SELECT trackid, artist, countview FROM tracklist ORDER BY countview DESC LIMIT 1

SELECT trackid, artist, countview FROM tracklist WHERE countview =(SELECT max(countview) FROM tracklist)

答案 3 :(得分:1)

SELECT * 
FROM tracklist 
WHERE countview = (SELECT MAX(countview) FROM tracklist)

答案 4 :(得分:0)

SELECT trackid,artist,MAX(countview)FROM tracklist GROUP BY trackid,artist