A comprehensive introduction to relational databases and SQL, focusing on fundamental query techniques including subqueries, date filtering, and data manipulation.
This project demonstrates proficiency in SQL fundamentals through a series of progressively challenging exercises. The exercises utilize a pizza delivery database schema to practice real-world query scenarios.
The project uses a relational database with five interconnected tables:
- pizzeria - Restaurant directory with ratings
- person - Customer information
- menu - Pizza offerings and prices by restaurant
- person_visits - Visit history to restaurants
- person_order - Order transaction records
- Writing SELECT queries with filtering and sorting
- Using comparison operators and BETWEEN clauses
- Working with subqueries in SELECT and FROM clauses
- Date range filtering and manipulation
- Calculated fields and conditional expressions (CASE statements)
- String concatenation and formatting
- Query optimization without JOINs
- Data analysis across multiple related tables
.
├── materials/
│ └── model.sql # Database schema and seed data
├── src/
│ ├── ex00/ # Basic SELECT queries
│ ├── ex01/ # Filtering and sorting
│ ├── ex02/ # Range queries
│ ├── ex03/ # Date filtering
│ ├── ex04/ # Calculated fields
│ ├── ex05/ # Subqueries in SELECT
│ ├── ex06/ # Conditional expressions
│ ├── ex07/ # CASE statements
│ ├── ex08/ # Modulo operations
│ └── ex09/ # Subqueries in FROM
└── README.md
- Ensure PostgreSQL is installed on your system
- Create a new database:
createdb pizza_db
- Load the database schema and data:
psql -d pizza_db -f materials/model.sql
- Run individual exercises:
psql -d pizza_db -f src/ex00/day00_ex00.sql
Select names and ages of people from a specific city.
Query with WHERE clause and ORDER BY on multiple conditions.
Two syntactically different approaches to range filtering (comparison operators vs BETWEEN).
Complex filtering with date ranges and multiple OR conditions.
String concatenation to create formatted output with proper quoting.
Using subqueries in the SELECT clause to retrieve related data.
Implementing boolean checks using CASE expressions.
Categorizing data into intervals using nested CASE statements.
Filtering results using modulo operations.
Complex queries using subqueries in the FROM clause for virtual tables.
Each exercise has specific requirements and restrictions:
- Language: ANSI SQL
- Some exercises prohibit JOINs and IN clauses to focus on alternative techniques
- Emphasis on subquery usage and creative problem-solving
- PostgreSQL (latest version recommended)
- SQL (ANSI standard)
This project develops fundamental SQL skills essential for:
- Data analysis and reporting
- Backend application development
- Database administration
- Understanding relational data models
This project is available under the MIT License. See LICENSE for details.
Note: This is an educational project focusing on SQL fundamentals and query construction techniques.
