0
SELECT DISTINCT(player2) FROM logs 
WHERE player1=3 
ORDER BY time DESC

是否可以使用该查询返回其他非不同的列?

或者我的其他解决方案:

SELECT * FROM logs 
WHERE player1=3 
GROUP BY player2 ORDER BY time DESC

这工作正常,但它没有正确订购。它选择组中的第一个。

表格示例:

player1 player2 time
3        5        1
3        5        2
3        6        3

我希望它会返回:

player2 time
5        2
6        3

但它返回(与分组):

player2 time
5        1
6        3
4

3 回答 3

4

试试这个:

SELECT player2, MAX(time) AS time
  FROM logs 
 WHERE player1=3 
 GROUP BY player2 
 ORDER BY time DESC
于 2012-07-18T17:37:04.987 回答
1
SELECT player2, max(`time`) as max_time
FROM logs 
WHERE player1 = 3 
GROUP BY player2 
于 2012-07-18T17:37:25.090 回答
0
SELECT player2, MAX(time) AS time   
FROM logs   
WHERE player1=3  
GROUP BY player2   
ORDER BY MAX(time) 
于 2012-07-18T17:42:51.907 回答