我有桌子,我存储足球比赛的结果 我存储了每个团队得分以及它的ID,我希望获得获胜团队的ID。
这是表格
team1_id team2_id team1_score team2_score
1 2 1 0
1 3 0 1
3 4 1 0
这就是我想要的结果
1
3
(第1队和第3队至少赢了一场比赛)
答案 0 :(得分:4)
试试这个:
SELECT DISTINCT IF(team1_score > team2_score, team1_id, team2_id) AS winner
FROM mytable