From d20c253e2baa818ec738b2fe10e35a71e8aeabea Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Sat, 28 Dec 2024 02:26:49 +0000 Subject: [PATCH] Improve challenges in SQL basics --- .../lessons/challenge-1.md | 55 +++++++++++++++++++ ...hallenge-2.md => expression-projection.md} | 4 +- .../{challenge-4.md => logical-operators.md} | 4 +- ...challenge-1.md => projection-challenge.md} | 2 +- ...hallenge-7.md => sorting-and-filtering.md} | 4 +- ...challenge-6.md => sorting-and-limiting.md} | 4 +- .../{challenge-5.md => sorting-challenge.md} | 4 +- .../{challenge-3.md => unique-projection.md} | 4 +- 8 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 src/data/courses/sql/chapters/data-definition-language/lessons/challenge-1.md rename src/data/courses/sql/chapters/sql-basics/lessons/{challenge-2.md => expression-projection.md} (97%) rename src/data/courses/sql/chapters/sql-basics/lessons/{challenge-4.md => logical-operators.md} (98%) rename src/data/courses/sql/chapters/sql-basics/lessons/{challenge-1.md => projection-challenge.md} (96%) rename src/data/courses/sql/chapters/sql-basics/lessons/{challenge-7.md => sorting-and-filtering.md} (97%) rename src/data/courses/sql/chapters/sql-basics/lessons/{challenge-6.md => sorting-and-limiting.md} (98%) rename src/data/courses/sql/chapters/sql-basics/lessons/{challenge-5.md => sorting-challenge.md} (98%) rename src/data/courses/sql/chapters/sql-basics/lessons/{challenge-3.md => unique-projection.md} (97%) diff --git a/src/data/courses/sql/chapters/data-definition-language/lessons/challenge-1.md b/src/data/courses/sql/chapters/data-definition-language/lessons/challenge-1.md new file mode 100644 index 000000000..53f5ca228 --- /dev/null +++ b/src/data/courses/sql/chapters/data-definition-language/lessons/challenge-1.md @@ -0,0 +1,55 @@ +--- +title: Challenge 1 +description: Write a SQL query to create a `books` table with specific columns. +order: 300 +type: challenge +initSteps: [] +expectedResults: + - columns: [message] + values: + - ['Table created successfully'] +--- + +You are tasked with creating a table named `books` for a bookstore database. The table should have the following columns: + +| Column Name | Data Type | Constraints | +| -------------- | -------------- | ----------------- | +| id | INTEGER | PRIMARY KEY | +| title | TEXT | NOT NULL | +| author | TEXT | NOT NULL | +| genre | TEXT | | +| price | NUMERIC(10, 2) | CHECK (price > 0) | +| published_date | DATE | | + +### Requirements + +1. The `id` column should uniquely identify each book. +2. The `title` and `author` columns cannot be null. +3. The `price` column must be greater than 0. + +### Task + +Write a SQL query to create the `books` table as described above. + +### Expected Output + +After running your query, the output should confirm the creation of the table: + +| message | +| -------------------------- | +| Table created successfully | + +### Example Query (Partial) + +```sql +CREATE TABLE books ( + id INTEGER PRIMARY KEY, + title TEXT NOT NULL, + author TEXT NOT NULL, + genre TEXT, + price NUMERIC(10, 2) CHECK (price > 0), + published_date DATE +); +``` + +Now, complete the challenge and create the table! diff --git a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-2.md b/src/data/courses/sql/chapters/sql-basics/lessons/expression-projection.md similarity index 97% rename from src/data/courses/sql/chapters/sql-basics/lessons/challenge-2.md rename to src/data/courses/sql/chapters/sql-basics/lessons/expression-projection.md index 90660d94a..56c56dd5b 100644 --- a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-2.md +++ b/src/data/courses/sql/chapters/sql-basics/lessons/expression-projection.md @@ -1,7 +1,7 @@ --- -title: Challenge 2 +title: Expression Projection description: Write a SQL query to find the total number of orders in the `orders` table. -order: 300 +order: 310 type: challenge initSteps: - CREATE TABLE books ( diff --git a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-4.md b/src/data/courses/sql/chapters/sql-basics/lessons/logical-operators.md similarity index 98% rename from src/data/courses/sql/chapters/sql-basics/lessons/challenge-4.md rename to src/data/courses/sql/chapters/sql-basics/lessons/logical-operators.md index 276313c86..e16ef9cbb 100644 --- a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-4.md +++ b/src/data/courses/sql/chapters/sql-basics/lessons/logical-operators.md @@ -1,7 +1,7 @@ --- -title: Challenge 4 +title: Logical Operators description: Write a SQL query to find the total number of orders in the `orders` table. -order: 400 +order: 340 type: challenge initSteps: - CREATE TABLE books ( diff --git a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-1.md b/src/data/courses/sql/chapters/sql-basics/lessons/projection-challenge.md similarity index 96% rename from src/data/courses/sql/chapters/sql-basics/lessons/challenge-1.md rename to src/data/courses/sql/chapters/sql-basics/lessons/projection-challenge.md index 6fd414db9..66bda88ed 100644 --- a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-1.md +++ b/src/data/courses/sql/chapters/sql-basics/lessons/projection-challenge.md @@ -1,5 +1,5 @@ --- -title: Challenge 1 +title: Projection Challenge description: Write a SQL query to find the total number of orders in the `orders` table. order: 300 type: challenge diff --git a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-7.md b/src/data/courses/sql/chapters/sql-basics/lessons/sorting-and-filtering.md similarity index 97% rename from src/data/courses/sql/chapters/sql-basics/lessons/challenge-7.md rename to src/data/courses/sql/chapters/sql-basics/lessons/sorting-and-filtering.md index 5c120c00d..f723257f1 100644 --- a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-7.md +++ b/src/data/courses/sql/chapters/sql-basics/lessons/sorting-and-filtering.md @@ -1,7 +1,7 @@ --- -title: Challenge 7 +title: Sorting and Filtering description: Write a SQL query to find the total number of orders in the `orders` table. -order: 700 +order: 370 type: challenge initSteps: - CREATE TABLE orders ( diff --git a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-6.md b/src/data/courses/sql/chapters/sql-basics/lessons/sorting-and-limiting.md similarity index 98% rename from src/data/courses/sql/chapters/sql-basics/lessons/challenge-6.md rename to src/data/courses/sql/chapters/sql-basics/lessons/sorting-and-limiting.md index 2d5bd63f9..a476c7d25 100644 --- a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-6.md +++ b/src/data/courses/sql/chapters/sql-basics/lessons/sorting-and-limiting.md @@ -1,7 +1,7 @@ --- -title: Challenge 6 +title: Sorting and Limiting description: Write a SQL query to find the total number of orders in the `orders` table. -order: 600 +order: 360 type: challenge initSteps: - CREATE TABLE orders ( diff --git a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-5.md b/src/data/courses/sql/chapters/sql-basics/lessons/sorting-challenge.md similarity index 98% rename from src/data/courses/sql/chapters/sql-basics/lessons/challenge-5.md rename to src/data/courses/sql/chapters/sql-basics/lessons/sorting-challenge.md index 7e29ca692..80c44385d 100644 --- a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-5.md +++ b/src/data/courses/sql/chapters/sql-basics/lessons/sorting-challenge.md @@ -1,7 +1,7 @@ --- -title: Challenge 5 +title: Sorting Challenge description: Write a SQL query to find the total number of orders in the `orders` table. -order: 500 +order: 350 type: challenge initSteps: - CREATE TABLE books ( diff --git a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-3.md b/src/data/courses/sql/chapters/sql-basics/lessons/unique-projection.md similarity index 97% rename from src/data/courses/sql/chapters/sql-basics/lessons/challenge-3.md rename to src/data/courses/sql/chapters/sql-basics/lessons/unique-projection.md index b902be8ad..1228e9ba9 100644 --- a/src/data/courses/sql/chapters/sql-basics/lessons/challenge-3.md +++ b/src/data/courses/sql/chapters/sql-basics/lessons/unique-projection.md @@ -1,7 +1,7 @@ --- -title: Challenge 3 +title: Unique Projection description: Write a SQL query to find the total number of orders in the `orders` table. -order: 300 +order: 330 type: challenge initSteps: - CREATE TABLE orders (