我正在运行的查询有问题。这是一个dbfiddle:https://dbfiddle.uk/?rdbms=mysql_5.6&fiddle=8dc0b4f201e7d25c8817dcecd35b47f0
[基本上,我想保持行的完整,我的意思是:您可以在第一个查询中看到playerID 147在2018-03-24 13:37:02上将得分设置为10450。但是,可悲的是,在第二个查询中,行中断了,我仍然可以获得所需的最低分数,但是日期是错误的。它设置为2018-03-05 16:24:28,即使它应该是2018-03-24 13:37:02。
我尝试执行此处描述的操作:How can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?,但无法正常工作。我不知道如何重写查询才能使其正常工作。我会很乐意帮助您更改查询。感谢您的帮助。
SELECT MIN(t.ID),t.Score,t.ChallengeId,t.playerID,MIN( from_unixtime(date) )
FROM `times` t inner Join
(SELECT MIN(Score) score,challengeID,playerID
from `times`
group by challengeID,playerID
Order by Score ASC) s
ON t.challengeID = s.challengeID
and t.playerID = s.playerID
and t.Score = s.score
GROUP BY t.Score,t.ChallengeId,t.playerID
order by t.Score
您得到此结果(仅显示第一个)>
ID Score ChallengeId playerID from_unixtime(date) 90488 10450 466 28 2018-03-20 02:16:29 92155 10450 466 8 2018-03-24 02:05:18 92448 10450 466 147 2018-03-24 13:37:02 92763 10450 466 97 2018-03-24 19:15:42 92787 10450 466 410 2018-03-24 19:23:24 85201 10460 466 255 2018-03-06 05:13:46 86256 10460 466 66 2018-03-09 10:48:16 92778 10460 466 1846 2018-03-24 19:21:07 84801 10470 466 47 2018-03-05 16:29:41 84804 10470 466 944 2018-03-05 16:30:34 85724 10470 466 599 2018-03-07 08:07:30 88139 10470 466 1651 2018-03-15 11:16:54
DBfiddle样本https://dbfiddle.uk/?rdbms=mysql_5.6&fiddle=de581e5a5b6fa9a184cc2e235337b2d5new