用于选择tot-goal和目标的SQL查询 [英] Sql query to select tot-goal and against goal

查看:67
本文介绍了用于选择tot-goal和目标的SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请求帮助我选择(Tot-Goals,Tot-Goals-against,Goal-Diff for Each Team)我使用的表叫做[Match Details],而且Fields是



* Tour-Id,Match Id,Team-Id,Goals *

1 1 1 1

1 1 2 1

1 1 1 1

1 2 1 1

1 2 3 1



我有什么试过:



Pleaes help me to select (Tot-Goals, Tot-Goals-against, Goal-Diff for Each Team) I am using Table called [Match Details] and Fields are

*Tour-Id, Match Id, Team-Id, Goals*
1 1 1 1
1 1 2 1
1 1 1 1
1 2 1 1
1 2 3 1

What I have tried:

SELECT Team-Id, SUM(Goals) as goals
FROM [Match Details]
WHERE [tourid] = Tour
GROUP BY club, tourid;

推荐答案

With played as
(
select tour_id ptour, match_id pmatch, team_id player, goals scored
from match_details
),
Versus as
(
Select tour_id vtour, match_id vmatch, team_id vplayer, goals conceded
From match_details
)
Select player, sum(scored) scored, sum(conceded) conceded, sum(scored - conceded) tot_diff
From played, versus
Where ptour = vtour
 and pmatch = vmatch
And player <> vplayer
Group by player;


这篇关于用于选择tot-goal和目标的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆