This repository contains a set of SQL exercises designed to help you practice and solidify your understanding of various SQL concepts and commands.
The exercises utilize the Sakila sample database, which simulates a movie rental store.
Concepts Covered:
- Basic Queries: Selecting data, filtering with
WHERE
, using operators likeAND
,OR
,IN
,NOT IN
,LIKE
,BETWEEN
, andREGEXP
. - Aggregate Functions: Using functions like
COUNT
,AVG
, andSUM
to perform calculations on data. - String Functions: Manipulating strings with functions like
CONCAT
. - Joins: Combining data from multiple tables using
INNER JOIN
. - Self Joins: Joining a table to itself to analyze relationships within the same table.
- Subqueries: Using nested queries to filter and refine results.
- Date Functions: Working with dates using functions like
DATEDIFF
.
Exercises:
The exercises cover a wide range of scenarios, including:
- Selecting specific data from tables (e.g., film titles, actor names).
- Filtering data based on various criteria (e.g., rating, length, release year).
- Calculating statistics (e.g., average film length, number of films per category).
- Joining tables to combine data (e.g., finding actors in specific films, counting rentals per category).
- Using subqueries to filter data based on complex conditions (e.g., finding actors who haven't been in horror films).
- Working with dates to calculate rental durations.
How to Use:
- Set up the Sakila Database: Download and install the Sakila database. Instructions can be found on the MySQL website.
- Run the Queries: Open the SQL file in MySQL Workbench and execute the queries.
- Analyze the Results: Examine the output of each query and compare it to the expected results.
- Review the Comments: Each query includes comments explaining the logic and the SQL concepts used.
Additional Notes:
- The exercises are designed to be progressively challenging, starting with basic queries and moving towards more complex scenarios.
- Feel free to modify the queries and experiment with different approaches.
- If you encounter any issues, refer to the MySQL documentation or online resources for assistance.
This set of exercises provides a comprehensive way to practice and improve your SQL skills. By working through them, you'll gain a deeper understanding of how to query and manipulate data effectively.