Add lesson 3: Sorting and LIMIT

Mira Kovac 1 year ago
parent 90068c8f24 commit 4402fdcc1a58f3fb111d9dd87d770338dbf3e896
3 changed files with 36 additions and 0 deletions
+21-0lessons/03-sorting-and-limit/README.md ADDED
@@ -0,0 +1,21 @@
1+# Lesson 3: Sorting and LIMIT
2+
3+We look at sorting and LIMIT the way working developers use it, with examples you can change and run right away.
4+
5+Full lesson: [https://glibcode.net/courses/sql-essentials/lessons/3](https://glibcode.net/courses/sql-essentials/lessons/3)
6+
7+## Files
8+
9+- `sorting.sql`: ORDER BY and LIMIT for top-N lists
10+
11+## Run it
12+
13+```sh
14+sqlite3 shop.db < ../../setup/schema.sql
15+sqlite3 shop.db < ../../setup/seed.sql
16+sqlite3 shop.db < sorting.sql
17+```
18+
19+## Exercises
20+
21+See [exercises.md](exercises.md). Ask in the forum once you've tried.
+5-0lessons/03-sorting-and-limit/exercises.md ADDED
@@ -0,0 +1,5 @@
1+# Exercises: lesson 3
2+
3+1. Make the example ask for its input instead of using a fixed value.
4+2. Find one thing in `sorting.sql` you could name better and rename it everywhere.
5+3. Add a check that prints a warning when a result looks wrong (negative, empty, too big).
+10-0lessons/03-sorting-and-limit/sorting.sql ADDED
@@ -0,0 +1,10 @@
1+-- The five most expensive products
2+SELECT name, price
3+FROM products
4+ORDER BY price DESC
5+LIMIT 5;
6+
7+-- Newest customers first, ties broken by name
8+SELECT name, signed_up
9+FROM customers
10+ORDER BY signed_up DESC, name;