Skip to content

LAB done#31

Open
vRUZIx wants to merge 1 commit intoironhack-labs:mainfrom
vRUZIx:main
Open

LAB done#31
vRUZIx wants to merge 1 commit intoironhack-labs:mainfrom
vRUZIx:main

Conversation

@vRUZIx
Copy link
Copy Markdown

@vRUZIx vRUZIx commented Mar 20, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 20, 2026 15:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds deliverables for the “SQL Normalization, DDL & Aggregation” lab: a SQL script implementing the exercises and a MySQL Workbench ERD model.

Changes:

  • Added LAB2SQL.sql with DDL, sample data (Exercise 1 + raw airline dataset), and Exercise 3 queries.
  • Added ERD_for_lab.mwb MySQL Workbench model file for ERD submission.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 10 comments.

File Description
LAB2SQL.sql Creates schemas/tables for normalization exercises and includes aggregation/join queries for Exercise 3.
ERD_for_lab.mwb Stores the ERD as a MySQL Workbench model archive.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +147 to +155
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
Copy link

Copilot AI Mar 20, 2026

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.

Suggested change
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 uses AI. Check for mistakes.
FOREIGN KEY (flight_id) REFERENCES flights(flight_id),
FOREIGN KEY (aircraft_id) REFERENCES aircrafts(aircraft_id)
);

Copy link

Copilot AI Mar 20, 2026

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.

Suggested change
-- 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 uses AI. Check for mistakes.
@@ -0,0 +1,159 @@
-- Challenge 1
create database lab;
use lab
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USE lab is missing a terminating semicolon, which will cause the next statement to be parsed incorrectly when running this as a script.

Suggested change
use lab
use lab;

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +6
CREATE TABLE articless (
author VARCHAR(100),
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The raw table is created as articless, but later statements reference articles. If this is meant to be the unnormalized dataset, consider naming it articles (or update later references) to avoid running into missing-table errors / confusion.

Copilot uses AI. Check for mistakes.
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;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These statements reference articles before it is created (SELECT * FROM articles; and DROP TABLE articles;), which will fail on a fresh database. If you need reset logic, use DROP TABLE IF EXISTS ... and place it before any selects/creates (and drop child tables before parent tables due to FKs).

Suggested change
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 uses AI. Check for mistakes.
Comment on lines +82 to +98
('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);
Copy link

Copilot AI Mar 20, 2026

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.

Suggested change
('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 uses AI. Check for mistakes.
customer_id INT AUTO_INCREMENT PRIMARY KEY,
name varchar(50),
status ENUM ('NONE','SILVER','GOLD'),
total_milage INT
Copy link

Copilot AI Mar 20, 2026

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.

Suggested change
total_milage INT
total_mileage INT

Copilot uses AI. Check for mistakes.
Comment on lines +107 to +144
CREATE TABLE flights (
flight_id INT AUTO_INCREMENT PRIMARY KEY,
flight_number VARCHAR(10) UNIQUE,
flight_mileage INT
);

CREATE TABLE aircrafts (
aircraft_id INT AUTO_INCREMENT PRIMARY KEY,
model VARCHAR(50) UNIQUE,
total_seats INT
);

CREATE TABLE bookings (
booking_id INT AUTO_INCREMENT PRIMARY KEY,
customer_id INT,
flight_id INT,
aircraft_id INT,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id),
FOREIGN KEY (flight_id) REFERENCES flights(flight_id),
FOREIGN KEY (aircraft_id) REFERENCES aircrafts(aircraft_id)
);

-- Challenge 3
-- 1
SELECT COUNT(DISTINCT flight_number) FROM flights;
-- 2
SELECT AVG(mileage) FROM flights;
-- 3
SELECT AVG(total_seats) FROM aircrafts;
-- 4
SELECT status, AVG(total_mileage) FROM customers GROUP BY status;
-- 5
SELECT status, MAX(total_mileage) FROM customers GROUP BY status;
-- 6
SELECT COUNT(*) FROM aircrafts WHERE name LIKE '%Boeing%';
-- 7
SELECT * FROM flights WHERE mileage BETWEEN 300 AND 2000;
-- 8
Copy link

Copilot AI Mar 20, 2026

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 uses AI. Check for mistakes.
Comment on lines +113 to +142
CREATE TABLE aircrafts (
aircraft_id INT AUTO_INCREMENT PRIMARY KEY,
model VARCHAR(50) UNIQUE,
total_seats INT
);

CREATE TABLE bookings (
booking_id INT AUTO_INCREMENT PRIMARY KEY,
customer_id INT,
flight_id INT,
aircraft_id INT,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id),
FOREIGN KEY (flight_id) REFERENCES flights(flight_id),
FOREIGN KEY (aircraft_id) REFERENCES aircrafts(aircraft_id)
);

-- Challenge 3
-- 1
SELECT COUNT(DISTINCT flight_number) FROM flights;
-- 2
SELECT AVG(mileage) FROM flights;
-- 3
SELECT AVG(total_seats) FROM aircrafts;
-- 4
SELECT status, AVG(total_mileage) FROM customers GROUP BY status;
-- 5
SELECT status, MAX(total_mileage) FROM customers GROUP BY status;
-- 6
SELECT COUNT(*) FROM aircrafts WHERE name LIKE '%Boeing%';
-- 7
Copy link

Copilot AI Mar 20, 2026

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 uses AI. Check for mistakes.
Comment on lines +148 to +155
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
Copy link

Copilot AI Mar 20, 2026

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants