-
Notifications
You must be signed in to change notification settings - Fork 48
LAB done #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
LAB done #31
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,159 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Challenge 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create database lab; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use lab | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE articless ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| author VARCHAR(100), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+6
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title VARCHAR(255), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| word_count INT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| views INT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| INSERT INTO articless (author, title, word_count, views) VALUES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ('Maria Charlotte', 'Best Paint Colors', 814, 14), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ('Juan Perez', 'Small Space Decorating Tips', 1146, 221), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ('Maria Charlotte', 'Hot Accessories', 986, 105), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ('Maria Charlotte', 'Mixing Textures', 765, 22), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ('Juan Perez', 'Kitchen Refresh', 1242, 307), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ('Maria Charlotte', 'Homemade Art Hacks', 1002, 193), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ('Gemma Alcocer', 'Refinishing Wood Floors', 1571, 7542); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- Solution 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- i made 2 (authors and Articles) table for 3NF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE authors ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id INT AUTO_INCREMENT PRIMARY KEY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name VARCHAR(100) NOT NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| select * from articles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| drop table articles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+29
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE authors ( | |
| id INT AUTO_INCREMENT PRIMARY KEY, | |
| name VARCHAR(100) NOT NULL | |
| ); | |
| select * from articles; | |
| drop table articles; | |
| DROP TABLE IF EXISTS articles; | |
| DROP TABLE IF EXISTS authors; | |
| CREATE TABLE authors ( | |
| id INT AUTO_INCREMENT PRIMARY KEY, | |
| name VARCHAR(100) NOT NULL | |
| ); |
Copilot
AI
Mar 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customer_status is defined as ENUM('NONE','SILVER','GOLD'), but the inserted values use mixed-case strings like 'Silver'/'Gold'/'None'. Depending on collation/settings this can insert as the empty enum value with warnings. Use the exact enum literals or change the enum to match the inserted values.
| ('Agustine Riviera', 'Silver', 'DL143', 'Boeing 747', 400, 135, 115235), | |
| ('Agustine Riviera', 'Silver', 'DL122', 'Airbus A330', 236, 4370, 115235), | |
| ('Alaina Sepulvida', 'None', 'DL122', 'Airbus A330', 236, 4370, 6008), | |
| ('Agustine Riviera', 'Silver', 'DL143', 'Boeing 747', 400, 135, 115235), | |
| ('Tom Jones', 'Gold', 'DL122', 'Airbus A330', 236, 4370, 205767), | |
| ('Tom Jones', 'Gold', 'DL53', 'Boeing 777', 264, 2078, 205767), | |
| ('Agustine Riviera', 'Silver', 'DL143', 'Boeing 747', 400, 135, 115235), | |
| ('Sam Rio', 'None', 'DL143', 'Boeing 747', 400, 135, 2653), | |
| ('Agustine Riviera', 'Silver', 'DL143', 'Boeing 747', 400, 135, 115235), | |
| ('Tom Jones', 'Gold', 'DL222', 'Boeing 777', 264, 1765, 205767), | |
| ('Jessica James', 'Silver', 'DL143', 'Boeing 747', 400, 135, 127656), | |
| ('Sam Rio', 'None', 'DL143', 'Boeing 747', 400, 135, 2653), | |
| ('Ana Janco', 'Silver', 'DL222', 'Boeing 777', 264, 1765, 136773), | |
| ('Jennifer Cortez', 'Gold', 'DL222', 'Boeing 777', 264, 1765, 300582), | |
| ('Jessica James', 'Silver', 'DL122', 'Airbus A330', 236, 4370, 127656), | |
| ('Sam Rio', 'None', 'DL37', 'Boeing 747', 400, 531, 2653), | |
| ('Christian Janco', 'Silver', 'DL222', 'Boeing 777', 264, 1765, 14642); | |
| ('Agustine Riviera', 'SILVER', 'DL143', 'Boeing 747', 400, 135, 115235), | |
| ('Agustine Riviera', 'SILVER', 'DL122', 'Airbus A330', 236, 4370, 115235), | |
| ('Alaina Sepulvida', 'NONE', 'DL122', 'Airbus A330', 236, 4370, 6008), | |
| ('Agustine Riviera', 'SILVER', 'DL143', 'Boeing 747', 400, 135, 115235), | |
| ('Tom Jones', 'GOLD', 'DL122', 'Airbus A330', 236, 4370, 205767), | |
| ('Tom Jones', 'GOLD', 'DL53', 'Boeing 777', 264, 2078, 205767), | |
| ('Agustine Riviera', 'SILVER', 'DL143', 'Boeing 747', 400, 135, 115235), | |
| ('Sam Rio', 'NONE', 'DL143', 'Boeing 747', 400, 135, 2653), | |
| ('Agustine Riviera', 'SILVER', 'DL143', 'Boeing 747', 400, 135, 115235), | |
| ('Tom Jones', 'GOLD', 'DL222', 'Boeing 777', 264, 1765, 205767), | |
| ('Jessica James', 'SILVER', 'DL143', 'Boeing 747', 400, 135, 127656), | |
| ('Sam Rio', 'NONE', 'DL143', 'Boeing 747', 400, 135, 2653), | |
| ('Ana Janco', 'SILVER', 'DL222', 'Boeing 777', 264, 1765, 136773), | |
| ('Jennifer Cortez', 'GOLD', 'DL222', 'Boeing 777', 264, 1765, 300582), | |
| ('Jessica James', 'SILVER', 'DL122', 'Airbus A330', 236, 4370, 127656), | |
| ('Sam Rio', 'NONE', 'DL37', 'Boeing 747', 400, 531, 2653), | |
| ('Christian Janco', 'SILVER', 'DL222', 'Boeing 777', 264, 1765, 14642); |
Copilot
AI
Mar 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The customers table defines total_milage, but later queries use total_mileage (with an 'e'), which will error. Rename the column or update the queries so the schema and queries match.
| total_milage INT | |
| total_mileage INT |
Copilot
AI
Mar 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exercise 2 Step 4 in the lab expects inserting the sample data into the normalized tables (customers, flights, aircrafts, bookings). Currently only flight_bookings is populated, so Exercise 3 queries against the normalized schema will return empty results even after fixing column names/joins. Add INSERTs (or INSERT...SELECT from flight_bookings) for the normalized tables.
| -- Insert sample data into normalized tables | |
| INSERT INTO customers (name, status, total_milage) VALUES | |
| ('Alice Johnson', 'GOLD', 25000), | |
| ('Bob Smith', 'SILVER', 12000), | |
| ('Carol Lee', 'NONE', 1500), | |
| ('David Brown', 'GOLD', 42000); | |
| INSERT INTO flights (flight_number, flight_mileage) VALUES | |
| ('FL100', 500), | |
| ('FL200', 1500), | |
| ('FL300', 3200); | |
| INSERT INTO aircrafts (model, total_seats) VALUES | |
| ('Boeing 737', 160), | |
| ('Airbus A320', 180), | |
| ('Boeing 777', 300); | |
| INSERT INTO bookings (customer_id, flight_id, aircraft_id) VALUES | |
| (1, 1, 1), | |
| (1, 2, 2), | |
| (2, 2, 2), | |
| (3, 1, 1), | |
| (4, 3, 3), | |
| (4, 2, 2); |
Copilot
AI
Mar 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The aircrafts table defines model, but the queries later use name (including LIKE '%Boeing%' and selecting/grouping by a.name). Align the column name in the schema and queries (either name everywhere or model everywhere).
Copilot
AI
Mar 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flights table uses flight_mileage, but the Exercise 3 queries reference mileage (e.g., AVG and BETWEEN). Either rename the column to mileage or update all queries to use flight_mileage consistently.
Copilot
AI
Mar 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The queries join on c.id / a.id, but the schema defines customers.customer_id and aircrafts.aircraft_id. Update the schema to use id as the PK (matching the provided query templates) or update the queries to use the actual PK column names.
| JOIN customers c ON b.customer_id = c.id | |
| JOIN flights f ON b.flight_number = f.flight_number | |
| GROUP BY c.status; | |
| -- 9 | |
| SELECT a.name, COUNT(*) AS total_bookings | |
| FROM bookings b | |
| JOIN customers c ON b.customer_id = c.id | |
| JOIN flights f ON b.flight_number = f.flight_number | |
| JOIN aircrafts a ON f.aircraft_id = a.id | |
| JOIN customers c ON b.customer_id = c.customer_id | |
| JOIN flights f ON b.flight_number = f.flight_number | |
| GROUP BY c.status; | |
| -- 9 | |
| SELECT a.name, COUNT(*) AS total_bookings | |
| FROM bookings b | |
| JOIN customers c ON b.customer_id = c.customer_id | |
| JOIN flights f ON b.flight_number = f.flight_number | |
| JOIN aircrafts a ON f.aircraft_id = a.aircraft_id |
Copilot
AI
Mar 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bookings table stores flight_id/aircraft_id, but the Exercise 3 queries join via b.flight_number = f.flight_number and f.aircraft_id = a.id. As written, those columns don’t exist on the referenced tables. Either (a) change bookings to store flight_number and reference aircraft_id from flights, or (b) update the queries to join via b.flight_id = f.flight_id and b.aircraft_id = a.aircraft_id.
| JOIN flights f ON b.flight_number = f.flight_number | |
| GROUP BY c.status; | |
| -- 9 | |
| SELECT a.name, COUNT(*) AS total_bookings | |
| FROM bookings b | |
| JOIN customers c ON b.customer_id = c.id | |
| JOIN flights f ON b.flight_number = f.flight_number | |
| JOIN aircrafts a ON f.aircraft_id = a.id | |
| JOIN flights f ON b.flight_id = f.flight_id | |
| GROUP BY c.status; | |
| -- 9 | |
| SELECT a.name, COUNT(*) AS total_bookings | |
| FROM bookings b | |
| JOIN customers c ON b.customer_id = c.id | |
| JOIN flights f ON b.flight_id = f.flight_id | |
| JOIN aircrafts a ON b.aircraft_id = a.aircraft_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
USE labis missing a terminating semicolon, which will cause the next statement to be parsed incorrectly when running this as a script.