我已经设法使其工作,但需要帮助改进查询并优化它以获取更多参数。
查询将计算赢得和输掉游戏的最长条纹,到目前为止,我已经设法通过获取胜出来使其成为单独的查询。但我想立即取两者。如何通过进一步构建此查询来实现这一目标(这将计算最长的连胜):
SELECT MIN( c.ID ) - a.ID + 1 as Streak
FROM games AS a
LEFT JOIN games AS b ON a.ID = b.id + 1 AND b.P1Outcome= 'win'
LEFT JOIN games AS c ON a.ID <= c.id AND c.P1Outcome= 'win'
LEFT JOIN games AS d ON c.ID = d.id - 1 AND d.P1Outcome= 'win'
WHERE
a.UsrID = x
AND a.P1Outcome= 'win'
AND b.ID IS NULL
AND c.ID IS NOT NULL
AND d.ID IS NULL
GROUP BY a.ID
ORDER BY Streak
ID =每场比赛的主键
P1Outcome =游戏中的用户结果
UsrID =用户ID
首先可以有任何改进,如果可能,它还可以同时获取连败吗?谢谢你的时间。