mysql计数null

发布于 2025-02-09 19:27:08 字数 710 浏览 3 评论 0原文

我有一个game1桌子, 似乎是这样的:

player1player2result_1result_2
team1 team1team210null
team1team310null
team2 team2team36null

result_1是player1的结果,result_2是player2的结果。

我想在下表:

播放器count_null
team10
Team21
Team32

请帮助我

I have a game1 table,
it seems like this:

player1player2result_1result_2
team1team210NULL
team1team310NULL
team2team36NULL

result_1 is player1's result and result_2 is player2's result.

I want to make below table:

playercount_null
team10
team21
team32

Please help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼藏柔 2025-02-16 19:27:08

您可以通过将表列“分配”成更多的行来做到这一点,然后按播放器(团队)进行分组,然后总和1当结果为null时

SELECT player, sum(if(result is null, 1, 0))
FROM (
  SELECT player1 as player, result_1 as result
  FROM game1
  UNION ALL
  SELECT player2 as player, result_2 as result
  FROM game1) t
GROUP BY player

You can do that by "dividing" the table columns into more rows, then group by player (team) and then sum 1 when the result is null

SELECT player, sum(if(result is null, 1, 0))
FROM (
  SELECT player1 as player, result_1 as result
  FROM game1
  UNION ALL
  SELECT player2 as player, result_2 as result
  FROM game1) t
GROUP BY player
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文