Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
Posted
Comments
Tomas Takac 22-Mar-17 7:57am    
What's wrong? Do you get an error? The results differ from expected?
Member 12480796 23-Mar-17 1:06am    
can u tell me, how to select (Tot-Goals, Tot-Goals-against, Goal-Diff for Each Team)

1 solution

SQL
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;
 
Share this answer
 
v2
Comments
RAMASWAMY EKAMBARAM 23-Mar-17 2:16am    
Keyed in the query from the phone and tried (unsuccessfully!) to put it in a code block. Thanks for doing it!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900