Get startedGet started for free

Slide to the right

Now let's see how FC Utrecht performs when they're the away team. You'll notice that the total for the season is at the bottom of the data set you queried. Depending on your results, this could be pretty long, and scrolling down is not very helpful.

In this exercise, you will slightly modify the query from the previous exercise by sorting the data set in reverse order and calculating a backward running total from the CURRENT ROW to the end of the data set (earliest record).

This exercise is part of the course

Data Manipulation in SQL

View Course

Exercise instructions

  • Complete the window function by:
    • Assessing the running total of away goals scored by FC Utrecht.
    • Assessing the running average of away goals scored.
    • Ordering both the running average and running total by date, descending.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

SELECT 
	-- Select the date and away goals
	___,
    ___,
    -- Create a running total and running average of away goals
    ___(away_goal) ___(ORDER BY ___ DESC
         ROWS BETWEEN ___ ___ AND ___ ___) AS running_total,
    ___(away_goal) ___(ORDER BY ___ DESC
         ROWS BETWEEN ___ ___ AND ___ ___) AS running_avg
FROM match
WHERE 
	awayteam_id = 9908 
    AND season = '2011/2012';
Edit and Run Code