我想這取決於條件,如果player_id(加里) 具有大於,等於或小於得分,然後player_id(「其他」)聚合條件?
我的架構具有
players(player_id, name)
matches(match_id, home_team(player_id), away_team(player_id))
outcome(outcome_id, match_id, home_score:integer, away_score:integer
輸出彙總:
select m.match_id, p.name AS home_team, p1.name AS away_team, o.home_score, o.away_score
from players p
inner join matches m on (p.player_id = m.home_team)
inner join players p1 on (p1.player_id = m.away_team)
inner join outcomes o on (m.match_id = o.match_id);
match_id | player_id | player_id | home_score | away_score
----------+-----------+-----------+------------+------------
1 | 1 | 2 | 1 | 2
2 | 2 | 1 | 1 | 3
3 | 3 | 1 | 3 | 2
求購輸出:
player_id | Wins | Draws | Losses
-------------+------+-------+--------
1 | 1 | 0 | 2
2 ... | ... | .. | ...
我的模式是可以修改的。
EDIT(sqlfiddle):http://www.sqlfiddle.com/#!2/7b6c8/1
啊遺憾的含混,這事doesent!重點更多的是贏得每場比賽的勝利和抽獎次數@Filipe Silva – skyw00lker
您可以在您的原始表格樣本數據中添加[sqlfiddle](http://www.sqlfiddle.com)嗎? –
會做! @FilipeSilva – skyw00lker