gpt4 book ai didi

mysql - 如何在mysql中选择输赢记录

转载 作者:行者123 更新时间:2023-11-29 09:26:37 25 4
gpt4 key购买 nike

我有看起来像这样的桌面“游戏”

| team1_id | team2_id | team1_pts | team2_pts |

1 3 101 117

2 5 99 98

我想做这样的选择,从表“团队”中返回团队名称和获胜/失败记录

| team_name | win | loss 

Boston 15 11

Miami 13 12

我想出了如何获取仅包含胜利次数的表格,但不知道如何在同一个表格中获取胜利和失败。

最佳答案

您可以取消旋转并重新加入:

select t.name, sum(is_win) as num_wins, sum(is_loss) as num_losses
from ((select (case when team1_pts > team2_pts then team1_id else team2_id end) as team_id,
1 as is_win, 0 as is_loss
from game g
) union all
(select (case when team1_pts < team2_pts then team1_id else team2_id end) as team_id,
0, 1
from game g
)
) g join
teams t
on t.team_id = g.team_id
group by t.name

关于mysql - 如何在mysql中选择输赢记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59507082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com