我有一个表结构,如:
Name Time
Joe 2012-02-22 22:11:26.0
Joe 2012-02-22 21:01:23.0
Sue 2012-02-22 20:57:10.0
john 2012-02-22 18:13:36.0
Fred 2012-02-22 16:56:57.0
Joe 2012-02-22 14:38:45.0
Joe 2012-02-22 14:38:45.0
Ralph 2012-02-22 14:26:20.0
... ...
(more Names and Times)
... ...
john 2010-03-10 15:27:39.0
john 2010-03-10 15:46:59.0
我正在寻找按时间排序的前 3 个名称。所以结果是:
Joe, Sue, john
我从如下查询开始:
SELECT Name FROM table ORDER BY LOWER(TIME) DESC
所以我想限制结果:
SELECT Name FROM table ORDER BY LOWER(TIME) DESC LIMIT 0 , 3
但结果显示了前 3 行:
Joe, Joe, Sue
现在我尝试先按名称对查询进行分组:
SELECT Name FROM table GROUP BY Name ORDER BY LOWER(TIME) DESC LIMIT 0 , 3
是的,这给了我 3 个不同的名字,但顺序不可复制。我在这里错过了什么吗?这里的正确语法是什么?