Add challenge 7

feat/course
Kamran Ahmed 4 weeks ago
parent a054649252
commit 5e19530f4e
  1. 56
      src/data/courses/sql/chapters/sql-basics/lessons/challenge-7.md
  2. 21
      src/data/courses/sql/chapters/sql-basics/lessons/handling-null-values.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 |

@ -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 |
Loading…
Cancel
Save