Skip to content
Advertisement

How do i crack this SQL Soccer Matches assignment?

I came across this problem recently, i’m a sql newbie preparing for an interview and i need some help understanding how to connect the tables without using joins (since there is no common column)to get the desired result

Compute the total number of points each team has scored after all the matches the rules are as follows

if a team wins a match(scores more goals than the other team) it gets 3 points.

if a team draws a match(scores exactly same number of goals as other team) it gets one point

if a team loses a match(scores fewer goals than other team) it gets no points.

write a query that returns a ranking of all teams(team_id) described in the table teams. for each team provide its name and number of points it received after all the matches(num_points). The table should be ordered by num_points in desc order. in case of a tie order the rows by team_id

Saw a solution that uses union all but it doesn’t provide the answer, tried modifying it myself too.

Advertisement

Answer

I suggest the following:

dbfiddle here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement