我認爲這是best solution。然而,這種查詢是解決不了我的問題 - 我有一個像這樣的表:mysql在羣組之前排序
+--+-------+-----+
|id|user_id|score|
+--+-------+-----+
|1 |1 |5 |
+--+-------+-----+
|2 |1 |16 |
+--+-------+-----+
|3 |1 |15 |
+--+-------+-----+
查詢:
SELECT *
FROM (`_scorboard`)
GROUP BY `user_id`
HAVING `score` = MAX(score)
ORDER BY `score` desc
result 0 rows
爲什麼它返回0的記錄?
這甚至執行? 'SELECT * ... GROUP BY ...'是一件很奇怪的事情! – 2011-05-08 23:04:54
[這裏](http://stackoverflow.com/questions/5140785/mysql-order-before-group-by/5140943#5140943),這樣的解決方案是由 – alioygur 2011-05-08 23:10:04
給出的,我這樣解決它,但我不認爲(t2.firstname,'',t2.lastname)AS全名 FROM(SELECT * FROM _scorboard ORDER BY score DESC)AS t1 LEFT JOIN _user_profile AS t2 ON(t1。 user_id = t2.user_id) GROUP BY t1.user_id LIMIT 0,20 – alioygur 2011-05-08 23:12:56