0

我有以下关系,

在此处输入图像描述

想知道我怎样才能让球队成为比赛的赢家?

4

1 回答 1

1
SELECT
  m.id_match,
  IF((id_home_team = ? AND score_home_team > score_away_team) OR
    (id_away_team = ? AND score_home_team < score_away_team), 1, 0) AS won
FROM matches m
  JOIN results r ON(r.id_match = m.id_match)
WHERE 
  id_home_team = ? OR id_away_team = ?

将 替换为?您团队的 ID。

SQL 小提琴中。

于 2012-08-24T16:56:35.173 回答