Refreshers on pure SQL

These questions test your core SQL that will be required before attempting the window function questions

You will require group by, If you are already comfortable with these then feel free to skip ahead

All questions are based around a table containing imaginary cats.


Read on to learn about Group By & Having

Group by & Having

  • Group by allows us to group data for use in aggregate functions (like sum, count & avg)
  • Having allows us to filter data from aggregate functions

Conside this table of runners

nameweightcountry
andy50UK
bob100UK
cedric50France
dave70Germany
eric70France

Consider a query where we wanted to find the average weight of the runners grouped by country. This can be done like this:

select
country,
avg(weight)
from runners group by country
countryavg_weight
UK75
France60
Germany70