Skip to content

Commit

Permalink
feat: add essential sql course
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesx00 committed Dec 18, 2024
1 parent 3e901aa commit 2a9a346
Show file tree
Hide file tree
Showing 26 changed files with 987 additions and 13 deletions.
9 changes: 7 additions & 2 deletions _includes/layouts/course.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ layout: layouts/base.njk
</p>
<div class="prose prose-headings:text-primary-900 max-w-none mb-16 font-victor-mono">
<h1 class="text-2xl md:text-3xl">{{ title }}</h1>
{% if is_under_development %}
<div class="mb-4">
<span class="text-sm text-red-600">This course is under development. New content is being added regularly.</span>
</div>
{% endif %}
{# {{ content | safe }} #}
</div>
<div class="text-sm">
Expand All @@ -18,8 +23,8 @@ layout: layouts/base.njk
{% if lesson.data.section %}
<p class="text-xl font-victor-mono font-bold mt-4 text-primary-700 mb-4">{{ lesson.data.section }}</p>
{% endif %}
<a href="{{ lesson.url }}" class="hover:underline block mb-2 font-light text-lg flex items-center">
<i class="fal fa-fw mr-1 fa-circle"></i>
<a href="{{ lesson.url }}" class="hover:underline mb-2 font-light text-lg flex items-center">
<i class="fal fa-fw mr-1 fa-circle"></i>
{{ lesson.data.lesson_name }}
</a>
</li>
Expand Down
10 changes: 10 additions & 0 deletions public/css/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,11 @@ h4 {
border-color: rgb(209 213 219 / var(--tw-border-opacity));
}

.border-red-500 {
--tw-border-opacity: 1;
border-color: rgb(239 68 68 / var(--tw-border-opacity));
}

.border-transparent {
border-color: transparent;
}
Expand Down Expand Up @@ -2218,6 +2223,11 @@ h4 {
color: rgb(239 68 68 / var(--tw-text-opacity));
}

.text-red-600 {
--tw-text-opacity: 1;
color: rgb(220 38 38 / var(--tw-text-opacity));
}

.text-red-800 {
--tw-text-opacity: 1;
color: rgb(153 27 27 / var(--tw-text-opacity));
Expand Down
9 changes: 0 additions & 9 deletions src/courses/basic-python/basic-python.11tydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,4 @@ module.exports = {
course_id: "basic-python",
course_name: "Basic Python for Beginners",
course_slug: "basic-python",
eleventyComputed: {
title: (data) => {
if (data.tags.indexOf("lesson") !== -1) {
return `${data.lesson_name} - ${data.course_name}`;
} else {
return data.title;
}
},
},
};
9 changes: 9 additions & 0 deletions src/courses/courses.11tydata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
module.exports = {
layout: "layouts/lesson.njk",
tags: ["lesson"], // This is set so that all subdirectories are tagged as lesson
eleventyComputed: {
title: (data) => {
if (data.tags.indexOf("lesson") !== -1) {
return `${data.lesson_name} - ${data.course_name}`;
} else {
return data.title;
}
},
},
};
55 changes: 55 additions & 0 deletions src/courses/essential-sql/1.1-course-introduction/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
lesson_name: Course introduction
code_editor: False
code_execution: False
adding_file_allowed: False
section: Introduction
---

## **Essential SQL Course** 😎

Welcome to the Essential SQL Course! 🚀 In this course, you will dive into the world of SQL (Structured Query Language) and learn the fundamental skills needed to work with databases effectively. SQL is a powerful language used to communicate with relational databases and is essential for anyone dealing with data management, analysis, or software development. This course will take you from a SQL beginner to a confident SQL user, empowering you to retrieve, manipulate, and analyze data efficiently.

### **What Will You Learn?** 📚

1. **SQL Basics:** Get introduced to SQL and relational databases.

2. **Retrieving Data:** Master the art of writing SQL queries to retrieve specific data from databases using SELECT statements. Explore filtering, sorting, and limiting results.

3. **Data Manipulation:** Understand how to insert, update, and delete data in SQL databases. Learn to modify existing records and add new data.

4. **Joining Tables:** Dive into the world of table joins to combine data from multiple tables effectively. Explore inner, outer, and cross joins.

5. **Data Filtering:** Learn about the WHERE clause and how to use it to filter data based on specific conditions.

6. **Aggregating Data:** Discover the power of aggregate functions like COUNT, SUM, AVG, MIN, and MAX to perform calculations on data sets.

7. **Grouping Data:** Understand GROUP BY and HAVING clauses to group and filter data for more advanced analysis.

8. **Subqueries:** Explore subqueries and how they can be used to create more complex SQL queries.

9. **Table Creation & Management:** Learn to create and manage database tables, define data types, and set up primary keys and constraints.

10. **Indexing:** Discover the concept of indexing to optimize query performance.

11. **Views and Stored Procedures:** Explore the creation of views and stored procedures to simplify complex queries and improve code reusability.

12. **Data Integrity and Transactions:** Understand the importance of data integrity and learn about transactions to maintain data consistency.

13. **Setup Your Own Database:** Learn how to set up and connect to databases using SQL Management Systems.

### **Who Is This Course For?** 🎯

- **Data Enthusiasts:** If you are passionate about data analysis, data science, or data management, learning SQL is a must. This course will provide you with the essential SQL skills to work with databases and extract valuable insights from data.

- **Software Developers:** SQL is a critical skill for developers who work with relational databases. Whether you are building web applications, enterprise systems, or mobile apps, this course will help you become proficient in SQL.

- **Business Professionals:** Managers, analysts, and decision-makers who deal with databases and data-driven insights can benefit greatly from understanding SQL. This course will empower you to access and analyze data efficiently, making better-informed decisions.

- **Students and Aspiring IT Professionals:** If you are a student pursuing a career in IT, software engineering, or data analysis, learning SQL will give you a competitive edge in the job market.

- **Entrepreneurs and Small Business Owners:** For those running businesses and handling databases, knowing SQL will enable you to manage data effectively and gain valuable business insights.

No prior SQL knowledge is required to take this course. As long as you have a curious mind and a desire to learn, you're welcome to join us on this exciting SQL learning journey!

So, are you ready to unleash the power of SQL and take control of your data? Enroll now and start mastering Essential SQL! 💪🔥
23 changes: 23 additions & 0 deletions src/courses/essential-sql/1.2-what-is-sql/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
lesson_name: What is SQL
code_editor: False
code_execution: False
adding_file_allowed: False
---

## What is SQL

**SQL (Structured Query Language)** is a specialized programming language used for managing and manipulating relational databases (we will cover what is relational databases in the next lesson). Its importance lies in its role as the standard language for interacting with databases, allowing users to perform various operations such as retrieving, updating, and managing data.

And because SQL is such a useful tool, primary users of SQL range from non-technical to highly technical professionals. For example:

- Database Administrators
- Data Analysts
- Data Scientists
- Software Developers
- Business Analysts
- Product Managers
- Financial Analysts
- Marketing Professionals

Throughout this course, we will cover everything you need to know in order to become proficient in SQL with fun challenges.
56 changes: 56 additions & 0 deletions src/courses/essential-sql/1.3-what-is-a-database/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
lesson_name: What is a Database
code_editor: False
code_execution: False
adding_file_allowed: False
---

## What is a database

![](https://asset.pythonexpert.dev/media/markdownx/2024/05/09/261196c9-716a-4723-9c9b-32b24899d461.jpg)

A database is a structured collection of data organized for efficientstorage, retrieval, and management. It serves as a centralized repository where information can be stored, updated, and accessed by various applications and users.

## What is relational database

A relational database is a type of database that uses a structure based on tables and the relationships between them. It follows the principles of the relational model, where data is organized into tables with rows and columns, and relationships between tables are defined.

### Example of popular relational databases

- MySQL: An open-source relational database management system (RDBMS).
Used in various applications, from small-scale websites to large enterprise systems.

- PostgreSQL: An open-source object-relational database system.
Known for its extensibility and support for complex queries.

- Microsoft SQL Server: A relational database management system developed by Microsoft.
Widely used in enterprise environments for data storage and retrieval.

- Oracle Database: A multi-model relational database management system.
Often used in large-scale enterprise applications.

- SQLite: A zero-configuration relational database engine. Suitable for embedded systems, mobile applications, and small to medium-sized websites.

With multiple options to choose from, one good thing about SQL is that how you write a command in an option could be very similar or even the same in another. We will be working with SQLite in this course, and will build our own PostgreSQL server with Amazon AWS.

### Data relationships

Data relationships are a fundamental aspect of how information is organized and interconnected in various domains. And almost everything in the world exhibits data relationships. Consider a company managing customer and order information:

- **Customers Table:**

| CustomerID | FirstName | LastName | Email |
| ---------- | --------- | -------- | ---------------- |
| 1 | John | Doe | [email protected] |
| 2 | Jane | Smith | [email protected] |
| 3 | Bob | Johnson | [email protected] |

- **Orders Table:**

| OrderID | CustomerID | Product | Quantity | OrderDate |
| ------- | ---------- | ---------- | -------- | ---------- |
| 101 | 1 | Laptop | 2 | 2023-02-15 |
| 102 | 2 | Smartphone | 1 | 2023-02-16 |
| 103 | 3 | Headphones | 3 | 2023-02-17 |

In this example, there are two tables: `Customers` and `Orders`. The `CustomerID` in the `Orders` table establishes a relationship with the `Customers` table, connecting orders to specific customers. We will cover data relationships further in the course.
40 changes: 40 additions & 0 deletions src/courses/essential-sql/2.1-select-a-single-column/files/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sqlite3
import os
from faker import Faker
from prettytable import from_db_cursor, MARKDOWN
from enum import Enum

def setup(connection):
fake = Faker()
Faker.seed(0)

cur = connection.cursor()

cur.execute("CREATE TABLE customers(first_name, last_name, age, gender)")

class Gender(Enum):
M = "M"
F = "F"

for i in range(10):
cur.execute(
"INSERT INTO customers (first_name, last_name, age, gender) VALUES (?, ?, ?, ?)",
(
fake.first_name(),
fake.last_name(),
fake.pyint(max_value=80) + 20,
fake.enum(Gender).value)
)

if __name__ == "__main__":

con = sqlite3.connect("tutorial.db")
cur = con.cursor()
setup(connection=con)
query = open('query.sql', 'r').read()
try:
res = cur.execute(query)
table = from_db_cursor(cur)
print(table)
except Exception as e:
print("Error:", str(e))
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sqlite3
import main
import sys
import json
from prettytable import from_db_cursor, MARKDOWN

con = sqlite3.connect("tutorial.db")
main.setup(connection=con)
cur = con.cursor()

try:
query = open('query.sql', 'r').read()
res = cur.execute(query)
result_columns = [] if cur.description is None else [c[0] for c in cur.description]

results = {}

results[1] = "first_name" in result_columns

sys.stdout.write(json.dumps(results))
except:
sys.stdout.write(json.dumps({}))
93 changes: 93 additions & 0 deletions src/courses/essential-sql/2.1-select-a-single-column/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
lesson_name: Select a single column
code_editor: True
code_execution: True
adding_file_allowed: False
section: Basic Data Retrieval
file_groups:
- common: false
files:
- file_name: query.sql
file_type: sql
id: 470
is_closable: false
is_edit_focus: true
is_editable: true
is_hidden: false
is_main: false
is_test_file: false
source: query.sql
- file_name: tests.py
file_type: python
id: 472
is_closable: false
is_edit_focus: false
is_editable: false
is_hidden: true
is_main: false
is_test_file: true
source: tests.py
- file_name: main.py
file_type: python
id: 471
is_closable: false
is_edit_focus: false
is_editable: false
is_hidden: true
is_main: true
is_test_file: false
source: main.py
id: 1
name: Python
---

## Select a single column

### What are SQL statements

SQL statements are commands used to perform operations on a relational database. These statements are essential for interacting with the database, whether it's for querying data, updating records, or managing the structure of the database.

### SELECT command

The `SELECT` command in SQL is used to retrieve data from one or more tables in a relational database. It allows users to specify the columns they want to retrieve, the table or tables from which to retrieve the data, and conditions to filter the results. The `SELECT` statement is a fundamental component of SQL queries and is extensively used for data retrieval and analysis.

The basic syntax of the `SELECT` statement is as follows:

```sql
SELECT column_name FROM table;
```

- `column_name`: Specify the column you want to retrieve.
- `table`: Specifies the table from which to retrieve the data.

<div class="alert-info text-sm">
<b>Semicolon after SQL Statements?</b><br />

Semicolon is the standard way to separate each SQL statement in database systems that allows more than one SQL statement to be executed in a single call.

Some database systems require a semicolon `;` at the end of each SQL statement.

In this course, we will use semicolon at the end of each SQL statement for clarity.

</div>

---

### Exercise

We have already created a table `customers` with the columns `first_name`, `last_name`, `age`, and `gender`. Write a command to retrieve `first_name` column from `customers` table.

#### Tests

<ul>
<li id="test-1">The result has <code>first_name</code> column.</li>
</ul>

<details class="border border-red-500 px-4 cursor-pointer">
<summary class="select-none">Solution</summary>

```sql
SELECT first_name FROM customers;
```

</details>
Loading

0 comments on commit 2a9a346

Please sign in to comment.