我有两张桌子......第一张桌子
id_klub || nama_klub
01 || manchester
02 || chelsea
03 || liverpool
04 || arsenal
第二张表
id_skor || Date || Home || Away || skor_home|| skor_away
0001 || 12/12/12 || 01 || 02 || 3 || 2
0002 || 13/12/12 || 02 || 03 || 2 || 2
0003 || 14/12/12 || 04 || 03 || 1 || 3
0004 || 15/12/12 || 04 || 01 || 3 || 1
在第二个表中主页和客场意味着id_club,例如:
当home = 01且away = 02表示manchester vs chealsea, 我的问题是,如何从那张桌子上制作积分榜?
club_name ||game ||win ||lose ||draw ||point
chelsea || 2 ||0 || 1 || 1 || 1
with logic
win = point +3;
lose = point +0;
draw = point +1;
我尝试过这个查询
SELECT nama_klub,
count(case when skor_home > skor_away then 1 end) wins,
count(case when skor_home < skor_away then 1 end) lose,
count(case when skor_home = skor_away then 1 end) draw,
sum(
case when skor_home > skor_away then 3 else 0 end
+ case when skor_home = skor_away then 1 else 0 end
) score
FROM klub INNER JOIN game ON klub.id_klub = game.home
GROUP BY id_skor
答案 0 :(得分:2)
您需要在Layout="_Layout"
表格中加入game
两次,一次在klub
上,一次在home
字段上,以获得团队参与的所有游戏英寸
然后你需要从2个表中添加条件计数以获得预期的输出,sg沿着下面的代码。
away