如何统计所有玩家的连输局数

2021-01-28 14:02:50 +08:00
 lbmjsls1

上一个问题 https://www.v2ex.com/t/749062 解决了,统计所有玩家的想不出来。用了 group by,各种不对。

2404 次点击
所在节点    MySQL
4 条回复
chotow
2021-01-28 14:50:12 +08:00
select g1.userid, count(if(g1.score < 0, 1, null)) as ret
from game as g1
left join game as g2 on g2.userid = g1.userid and g2.score > 0 and g2.id > g1.id
where g2.id is null
group by g1.userid
lbmjsls1
2021-01-28 15:39:29 +08:00
@chotow 多谢,测试下来是正确的。看了半天才看懂。
xing7673
2021-01-28 18:57:54 +08:00
就喜欢这种二话不说拍代码的硬核老哥
q9OxQg
2021-01-29 01:24:22 +08:00
连我这非 IT 人士都给一楼点了个赞,并读了代码。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/749215

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX