diff --git a/Top-Travellers.txt b/Top-Travellers.txt new file mode 100644 index 0000000..f9d10ab --- /dev/null +++ b/Top-Travellers.txt @@ -0,0 +1,2 @@ +select u.name, IFNULL(sum(r.distance),0) as travelled_distance from users u +LEFT JOIN rides r ON u.id = r.user_id GROUP BY r.user_id ORDER BY travelled_distance DESC, u.name; diff --git a/apples_and_oranges.txt b/apples_and_oranges.txt new file mode 100644 index 0000000..8a860d6 --- /dev/null +++ b/apples_and_oranges.txt @@ -0,0 +1,2 @@ +with apple as (select sale_date, sold_num from sales where fruit = 'apples'), orange as (select sale_date, sold_num from sales where fruit = 'oranges') +select a.sale_date, (a.sold_num - o.sold_num) as diff from apple a join orange o on o.sale_date = a.sale_date;