【发布时间】:2011-08-21 07:38:49
【问题描述】:
我认为这是best solution。但是,这个查询并不能解决我的问题 - 我喜欢这张表:
+--+-------+-----+
|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 ...是一件很奇怪的事情! -
here,这样的解决方案是由
-
我是这样解决的,但我认为这不是正确的解决方案 SELECT t1.*, CONCAT(t2.firstname, ' ', t2.lastname) AS fullname 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
标签: mysql sql aggregate-functions