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
name | weight | country |
---|---|---|
andy | 50 | UK |
bob | 100 | UK |
cedric | 50 | France |
dave | 70 | Germany |
eric | 70 | France |
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
country | avg_weight |
---|---|
UK | 75 |
France | 60 |
Germany | 70 |