From d5c9b6cf8e99a8cc030286cdab7791ed566bfdb2 Mon Sep 17 00:00:00 2001 From: itsAbilash <102655634+itsAbilash@users.noreply.github.com> Date: Mon, 27 Jan 2025 11:30:02 -0600 Subject: [PATCH 1/2] Create Top-Travellers.txt --- Top-Travellers.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Top-Travellers.txt 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; From 354d1a03bce3750f514ef2ad4fee1b6775ea55bb Mon Sep 17 00:00:00 2001 From: itsAbilash <102655634+itsAbilash@users.noreply.github.com> Date: Mon, 27 Jan 2025 11:39:59 -0600 Subject: [PATCH 2/2] Create apples_and_oranges.txt --- apples_and_oranges.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 apples_and_oranges.txt 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;