需要帮助更改我的查询以保持最小行数不变
Need help altering my query to keep min rows intact
我 运行 的查询有问题。这是一个 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声明
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=de581e5a5b6fa9a184cc2e235337b2d5
我 运行 的查询有问题。这是一个 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声明
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=de581e5a5b6fa9a184cc2e235337b2d5