From 558c3c389403c6f47e38d55cd9980d0d528d468d Mon Sep 17 00:00:00 2001
From: debironhack <103188679+debironhack@users.noreply.github.com>
Date: Thu, 20 Apr 2023 17:42:24 +0200
Subject: [PATCH 1/7] Add files via upload
---
lab-sql-basic-queries.md | 100 +++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)
create mode 100644 lab-sql-basic-queries.md
diff --git a/lab-sql-basic-queries.md b/lab-sql-basic-queries.md
new file mode 100644
index 0000000..ee88817
--- /dev/null
+++ b/lab-sql-basic-queries.md
@@ -0,0 +1,100 @@
+
+
+# Lab | SQL Basic Queries
+
+
+
+ Learning Goals
+
+
+ This lab allows you to practice and apply the concepts and techniques taught in class.
+
+ Upon completion of this lab, you will be able to:
+
+- Use SQL queries to extract insights from the data and answer research questions or problem statements, using techniques such as selecting columns with SELECT clause, filtering with WHERE clause, sorting data with ORDER BY clause, limiting results with LIMIT, using DISTINCT to retrieve unique values, and counting records with COUNT.
+
+
+
+
+
+
+
+
+
+ Prerequisites
+
+
+Before this starting this lab, you should have learnt about:
+
+- SELECT, FROM, ORDER BY, LIMIT, WHERE clauses.
+- DISTINCT keyword to return only unique values, AS keyword for using aliases, COUNT function for counting records.
+
+
+
+
+
+
+## Introduction
+
+Welcome to the SQL Basic Queries lab!
+
+In this lab, you will practice how to use SQL queries to extract insights from the [Sakila](https://dev.mysql.com/doc/sakila/en/) database which contains information about movie rentals.
+
+In this lab, you'll practice the basics of SQL, including how to select data from tables, filter results using the WHERE clause, aggregate data with functions like COUNT, and sort results using the ORDER BY clause.
+
+Throughout the lab, you will work with two SQL query files: `sakila-schema.sql`, which creates the database schema, and `sakila-data.sql`, which inserts the data into the database. You can download the necessary files locally by following the steps listed in [Sakila sample database - installation](https://dev.mysql.com/doc/sakila/en/sakila-installation.html).
+
+You can also use the Entity Relationship Diagram (ERD) of the database to guide your analysis:
+
+
+
+
+
+
+
+
+## Challenge
+Use the sakila database to do the following tasks:
+
+1. Show all tables.
+2. Retrieve all the data from the tables `actor`, `film` and `customer`.
+3. Retrieve the following columns from their respective tables:
+ - 3.1 Titles of all films from the film table
+ - 3.2. List of languages used in films, with the column aliased as language from the language table
+ - 3.3 List of first names of all employees from the staff table
+
+4. Retrieve unique release years.
+5. Counting records for database insights:
+ - 5.1 Determine the number of stores that the company has.
+ - 5.2 Determine the number of employees that the company has.
+ - 5.3 Determine how many films are available for rent and how many have been rented.
+ - 5.4 Determine the number of distinct last names of the actors in the database.
+6. Retrieve the 10 longest films.
+7. Use filtering techniques in order to:
+ - 7.1 Retrieve all actors with the first name "SCARLETT".
+ - 7.2 Retrieve all movies that have ARMAGEDDON in their title and have a duration longer than 100 minutes.
+
+ - *Hint: use `LIKE` operator. [More information here.](https://www.w3schools.com/sql/sql_like.asp)*
+ - 7.3 Determine the number of films that include Behind the Scenes content
+
+## Requirements
+
+- Fork this repo
+- Clone it to your machine
+
+
+## Getting Started
+
+Complete the challenges in this readme in a `.sql`file.
+
+## Submission
+
+- Upon completion, run the following commands:
+
+```bash
+git add .
+git commit -m "Solved lab"
+git push origin master
+```
+
+- Create a Pull Request so that your TAs can check your work.
\ No newline at end of file
From 457828e33189784b5665a7ff5822cd1abd4e6089 Mon Sep 17 00:00:00 2001
From: sandrabosk
Date: Tue, 23 May 2023 20:36:33 +0200
Subject: [PATCH 2/7] rename file
---
lab-sql-basic-queries.md => README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
rename lab-sql-basic-queries.md => README.md (99%)
diff --git a/lab-sql-basic-queries.md b/README.md
similarity index 99%
rename from lab-sql-basic-queries.md
rename to README.md
index ee88817..29d54c5 100644
--- a/lab-sql-basic-queries.md
+++ b/README.md
@@ -1,6 +1,6 @@

-# Lab | SQL Basic Queries
+# LAB | SQL Basic Queries
From 8b2237483810f88ea35d83f2aad374559551d0dc Mon Sep 17 00:00:00 2001
From: debironhack <103188679+debironhack@users.noreply.github.com>
Date: Wed, 26 Jul 2023 15:20:34 +0200
Subject: [PATCH 3/7] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 29d54c5..2d5d413 100644
--- a/README.md
+++ b/README.md
@@ -97,4 +97,4 @@ git commit -m "Solved lab"
git push origin master
```
-- Create a Pull Request so that your TAs can check your work.
\ No newline at end of file
+- Paste the link of your lab in Student Portal.
From b1ad4aba317c8a5252406c4b48a672ad3eda08f8 Mon Sep 17 00:00:00 2001
From: Oliver Juggins
Date: Thu, 5 Oct 2023 17:45:43 +0200
Subject: [PATCH 4/7] Minor updates to Lab
---
README.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 2d5d413..354dc4f 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,7 @@ In this lab, you'll practice the basics of SQL, including how to select data fro
Throughout the lab, you will work with two SQL query files: `sakila-schema.sql`, which creates the database schema, and `sakila-data.sql`, which inserts the data into the database. You can download the necessary files locally by following the steps listed in [Sakila sample database - installation](https://dev.mysql.com/doc/sakila/en/sakila-installation.html).
-You can also use the Entity Relationship Diagram (ERD) of the database to guide your analysis:
+You can also refer to the Entity Relationship Diagram (ERD) of the database to guide your analysis:
@@ -56,12 +56,12 @@ You can also use the Entity Relationship Diagram (ERD) of the database to guide
## Challenge
Use the sakila database to do the following tasks:
-1. Show all tables.
+1. Display all available tables in the Sakila database.
2. Retrieve all the data from the tables `actor`, `film` and `customer`.
3. Retrieve the following columns from their respective tables:
- - 3.1 Titles of all films from the film table
- - 3.2. List of languages used in films, with the column aliased as language from the language table
- - 3.3 List of first names of all employees from the staff table
+ - 3.1 Titles of all films from the `film` table
+ - 3.2 List of languages used in films, with the column aliased as `language` from the `language` table
+ - 3.3 List of first names of all employees from the `staff` table
4. Retrieve unique release years.
5. Counting records for database insights:
From 868e4668819234170d9a351e1899b1ebf85368e9 Mon Sep 17 00:00:00 2001
From: debironhack <103188679+debironhack@users.noreply.github.com>
Date: Tue, 10 Oct 2023 18:10:04 +0200
Subject: [PATCH 5/7] adding "bonus" for some queries
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index 354dc4f..e2c8dcb 100644
--- a/README.md
+++ b/README.md
@@ -72,6 +72,8 @@ Use the sakila database to do the following tasks:
6. Retrieve the 10 longest films.
7. Use filtering techniques in order to:
- 7.1 Retrieve all actors with the first name "SCARLETT".
+
+ BONUS:
- 7.2 Retrieve all movies that have ARMAGEDDON in their title and have a duration longer than 100 minutes.
- *Hint: use `LIKE` operator. [More information here.](https://www.w3schools.com/sql/sql_like.asp)*
From ac75c662fbe07011fa2f1bd57ae01e4ad323d735 Mon Sep 17 00:00:00 2001
From: Ironhack Education Team
Date: Fri, 15 Nov 2024 11:59:35 +0100
Subject: [PATCH 6/7] Added submission info for AI Feedback
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index e2c8dcb..374b48b 100644
--- a/README.md
+++ b/README.md
@@ -99,4 +99,5 @@ git commit -m "Solved lab"
git push origin master
```
+- Please only include a .sql file with your solution, not the sakila files
- Paste the link of your lab in Student Portal.
From 0aafb59e750da8245a1aef2ecb876b0fe4e1c322 Mon Sep 17 00:00:00 2001
From: aroaxinping <239125952+aroaxinping@users.noreply.github.com>
Date: Tue, 4 Aug 2026 10:24:17 +0200
Subject: [PATCH 7/7] Solved lab
---
lab-sql-basic-queries.sql | 61 +++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 lab-sql-basic-queries.sql
diff --git a/lab-sql-basic-queries.sql b/lab-sql-basic-queries.sql
new file mode 100644
index 0000000..9141098
--- /dev/null
+++ b/lab-sql-basic-queries.sql
@@ -0,0 +1,61 @@
+USE sakila;
+
+-- 1. Display all available tables in the Sakila database.
+SHOW TABLES;
+
+-- 2. Retrieve all the data from the tables actor, film and customer.
+SELECT * FROM actor;
+SELECT * FROM film;
+SELECT * FROM customer;
+
+-- 3.1 Titles of all films
+SELECT title FROM film;
+
+-- 3.2 List of languages, aliased as `language`
+SELECT name AS language FROM language;
+
+-- 3.3 First names of all employees from the staff table
+SELECT first_name FROM staff;
+
+-- 4. Retrieve unique release years.
+SELECT DISTINCT release_year FROM film;
+
+-- 5.1 Number of stores
+SELECT COUNT(*) AS number_of_stores FROM store;
+
+-- 5.2 Number of employees
+SELECT COUNT(*) AS number_of_employees FROM staff;
+
+-- 5.3 How many films are available for rent, and how many have been rented
+-- "available for rent" = distinct films that exist in inventory (a copy exists to rent)
+-- "have been rented" = distinct films that show up in the rental history at least once
+SELECT COUNT(DISTINCT film_id) AS films_available_for_rent
+FROM inventory;
+
+SELECT COUNT(DISTINCT inventory.film_id) AS films_rented_at_least_once
+FROM rental
+JOIN inventory ON rental.inventory_id = inventory.inventory_id;
+-- both come back as 958 -- every film currently in inventory has been rented at least once
+
+-- 5.4 Number of distinct last names of actors
+SELECT COUNT(DISTINCT last_name) AS distinct_actor_last_names FROM actor;
+
+-- 6. Retrieve the 10 longest films.
+SELECT title, length
+FROM film
+ORDER BY length DESC
+LIMIT 10;
+
+-- 7.1 All actors with the first name "SCARLETT"
+SELECT * FROM actor
+WHERE first_name = 'SCARLETT';
+
+-- BONUS 7.2 Movies with ARMAGEDDON in the title, duration > 100 minutes
+SELECT title, length
+FROM film
+WHERE title LIKE '%ARMAGEDDON%' AND length > 100;
+
+-- BONUS 7.3 Number of films that include Behind the Scenes content
+SELECT COUNT(*) AS films_with_behind_the_scenes
+FROM film
+WHERE special_features LIKE '%Behind the Scenes%';