From 5e19530f4e6ee4492c2a0e264519852da35398cd Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Wed, 25 Dec 2024 13:14:34 +0000 Subject: [PATCH] Add challenge 7 --- .../sql-basics/lessons/challenge-7.md | 56 +++++++++++++++++++ .../lessons/handling-null-values.md | 21 +------ 2 files changed, 57 insertions(+), 20 deletions(-) create mode 100644 src/data/courses/sql/chapters/sql-basics/lessons/challenge-7.md diff --git a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-7.md b/src/data/courses/sql/chapters/sql-basics/lessons/challenge-7.md new file mode 100644 index 000000000..5c120c00d --- /dev/null +++ b/src/data/courses/sql/chapters/sql-basics/lessons/challenge-7.md @@ -0,0 +1,56 @@ +--- +title: Challenge 7 +description: Write a SQL query to find the total number of orders in the `orders` table. +order: 700 +type: challenge +initSteps: + - CREATE TABLE orders ( + id INTEGER PRIMARY KEY, + customer_name TEXT NOT NULL, + total_amount REAL NOT NULL, + shipped_at DATE + ); + - INSERT INTO orders (id, customer_name, total_amount, shipped_at) VALUES + (1, 'Alice', 100, '2024-01-01'), + (2, 'Bob', 200, NULL), + (3, 'Charlie', 300, '2024-01-03'), + (4, 'David', 400, NULL), + (5, 'Eve', 500, '2024-01-05'), + (6, 'Frank', 600, NULL), + (7, 'Grace', 700, '2024-01-07'), + (8, 'Henry', 800, NULL), + (9, 'Henry', 900, '2024-01-09'), + (10, 'Ivy', 1000, NULL); + +expectedResults: + - columns: [id, customer_name, total_amount, shipped_at] + values: + - [10, 'Ivy', 1000, NULL] + - [8, 'Henry', 800, NULL] + - [6, 'Frank', 600, NULL] +--- + +Given the following table for `orders`: + +| id | customer_name | total_amount | shipped_at | +| --- | ------------- | ------------ | ---------- | +| 1 | Alice | 100 | 2024-01-01 | +| 2 | Bob | 200 | NULL | +| 3 | Charlie | 300 | 2024-01-03 | +| 4 | David | 400 | NULL | +| 5 | Eve | 500 | 2024-01-05 | +| 6 | Frank | 600 | NULL | +| 7 | Grace | 700 | 2024-01-07 | +| 8 | Henry | 800 | NULL | +| 9 | Henry | 900 | 2024-01-09 | +| 10 | Ivy | 1000 | NULL | + +Write an SQL query to return the top 3 most expensive orders that don't have a `shipped_at` date. + +## Expected Results + +| id | customer_name | total_amount | shipped_at | +| --- | ------------- | ------------ | ---------- | +| 10 | Ivy | 1000 | NULL | +| 8 | Henry | 800 | NULL | +| 6 | Frank | 600 | NULL | diff --git a/src/data/courses/sql/chapters/sql-basics/lessons/handling-null-values.md b/src/data/courses/sql/chapters/sql-basics/lessons/handling-null-values.md index c717d0a90..2b5217609 100644 --- a/src/data/courses/sql/chapters/sql-basics/lessons/handling-null-values.md +++ b/src/data/courses/sql/chapters/sql-basics/lessons/handling-null-values.md @@ -87,23 +87,4 @@ This query will return the name of the customer and their phone number. If the p | Henry | - missing - | henry@example.com | | Charlie | 555-555-5555 | charlie@example.com | | Eve | 555-777-8888 | eve@example.com | -| Grace | 555-444-3333 | grace@example.com | - ---- - -## Challenge - -Given the following table for `orders` write a query to return the top 3 most expensive orders that don't have a `shipped_at` date. - -| id | customer_id | total_amount | shipped_at | -| --- | ----------- | ------------ | ---------- | -| 1 | 1 | 100 | 2024-01-01 | -| 2 | 2 | 200 | NULL | -| 3 | 3 | 300 | 2024-01-03 | -| 4 | 4 | 400 | NULL | -| 5 | 5 | 500 | 2024-01-05 | -| 6 | 6 | 600 | NULL | -| 7 | 7 | 700 | 2024-01-07 | -| 8 | 8 | 800 | NULL | -| 9 | 9 | 900 | 2024-01-09 | -| 10 | 10 | 1000 | NULL | +| Grace | 555-444-3333 | grace@example.com | \ No newline at end of file