我有一个问题来创建SQL语句
我有2张桌子:团队和杯子
table Teams :team id, team
table Cups:team_id, EuroCup, Worldcup
目前我有:
select t.team as Stats,sum(Eurocups) as Value
from cups c
join team t
on c.team_id=t.team_id
where c.team_id = 3 or c.team_id=1
group by t.team
给我
Stats Value
Spain 2
France 3
我希望创建SQL查询,这比较了2个不同的团队,例如:
Stats Value1 Value2
Eurocups 2 3
所有这些用于Google图表堆叠的条形图,它将从MySQL中获取数据并转换为JSON,例如
var data = google.visualization.arrayToDataTable([
['Stats', 'Value1', 'Value2'],
['Eurocups', 2, 3 ],
['Worldcups', 1, 2 ]
]);
类似的东西:
select t.team as Stats,
(select sum(t1.Eurocups) from cups t1 where t1.team_id = 3) as Value1,
(select sum(t2.Eurocups) from cups t2 where t2.team_id = 1) as Value2
from cups c
join team t
on c.team_id=t.team_id
where c.team_id = 3 or c.team_id=1
group by t.team