diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..30cf57e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/exercise.sql b/.idea/exercise.sql new file mode 100644 index 0000000..7cbe1fe --- /dev/null +++ b/.idea/exercise.sql @@ -0,0 +1,147 @@ +# Exercise 0.1 +# Create the category table with the following columns: +# +# Column Type Constraint +# category_id VARCHAR(10) Primary key, NOT NULL +# category_name VARCHAR(100) NOT NULL +# tax_rate DECIMAL(4,2) — + + + +USE hello_amazon0326; + +CREATE TABLE category ( + category_id VARCHAR(10) NOT NULL, + category_name VARCHAR(100) NOT NULL, + tax_rate DECIMAL(4, 2), + PRIMARY KEY(category_id) +); +CREATE TABLE Authors ( + author_id INT PRIMARY KEY AUTO_INCREMENT, + author_name VARCHAR(255) NOT NULL +); + +CREATE TABLE Articles ( + article_id INT PRIMARY KEY AUTO_INCREMENT, + author_id INT, + title VARCHAR(255) NOT NULL, + word_count INT, + views INT, + FOREIGN KEY (author_id) REFERENCES Authors(author_id) +); +INSERT INTO Authors (author_name) VALUES + ('Maria Charlotte'), + ('Juan Perez'), + ('Gemma Alcocer'); + +-- Insert articles using the corresponding author_id +INSERT INTO Articles (author_id, title, word_count, views) VALUES + (1, 'Best Paint Colors', 814, 14), + (2, 'Small Space Decorating Tips', 1146, 221), + (1, 'Hot Accessories', 986, 105), + (1, 'Mixing Textures', 765, 22), + (2, 'Kitchen Refresh', 1242, 307), + (1, 'Homemade Art Hacks', 1002, 193), + (3, 'Refinishing Wood Floors', 1571, 7542); + +-- 1. Tabella Aeromobili (Risolve la dipendenza transitiva tra volo e posti) +CREATE TABLE Aircraft ( + aircraft_model VARCHAR(50) PRIMARY KEY, + total_seats INT NOT NULL +); + +-- 2. Tabella Clienti (Raggruppa status e miglia totali) +CREATE TABLE Customers ( + customer_id INT PRIMARY KEY AUTO_INCREMENT, + customer_name VARCHAR(100) NOT NULL, + customer_status VARCHAR(20), + total_customer_mileage INT +); + +-- 3. Tabella Voli (Specifica la tratta e l'aereo assegnato) +CREATE TABLE Flights ( + flight_number VARCHAR(10) PRIMARY KEY, + aircraft_model VARCHAR(50), + flight_mileage INT, + FOREIGN KEY (aircraft_model) REFERENCES Aircraft(aircraft_model) +); + +-- 4. Tabella Prenotazioni (Tabella di giunzione molti-a-molti) +CREATE TABLE Flight_Log ( + customer_id INT, + flight_number VARCHAR(10), + PRIMARY KEY (customer_id, flight_number), + FOREIGN KEY (customer_id) REFERENCES Customers(customer_id), + FOREIGN KEY (flight_number) REFERENCES Flights(flight_number) +); + +-- Inserimento dati Aeromobili +INSERT INTO Aircraft (aircraft_model, total_seats) VALUES + ('Boeing 747', 400), + ('Airbus A330', 236), + ('Boeing 777', 264); + +-- Inserimento dati Clienti +INSERT INTO Customers (customer_name, customer_status, total_customer_mileage) VALUES + ('Agustine Riviera', 'Silver', 115235), + ('Alaina Sepulvida', 'None', 6008), + ('Tom Jones', 'Gold', 205767), + ('Sam Rio', 'None', 2653), + ('Jessica James', 'Silver', 127656), + ('Ana Janco', 'Silver', 136773), + ('Jennifer Cortez', 'Gold', 300582), + ('Christian Janco', 'Silver', 14642); + +-- Inserimento dati Voli +INSERT INTO Flights (flight_number, aircraft_model, flight_mileage) VALUES + ('DL143', 'Boeing 747', 135), + ('DL122', 'Airbus A330', 4370), + ('DL53', 'Boeing 777', 2078), + ('DL222', 'Boeing 777', 1765), + ('DL37', 'Boeing 747', 531); + +-- Inserimento dati Log Voli (unici, rimuovendo i duplicati del dataset raw) +INSERT INTO Flight_Log (customer_id, flight_number) VALUES + (1, 'DL143'), (1, 'DL122'), + (2, 'DL122'), + (3, 'DL122'), (3, 'DL53'), (3, 'DL222'), + (4, 'DL143'), (4, 'DL37'), + (5, 'DL143'), (5, 'DL122'), + (6, 'DL222'), + (7, 'DL222'), + (8, 'DL222'); + + +SELECT COUNT(*) FROM flights; +SELECT AVG(flight_mileage) FROM flights; +SELECT AVG(total_aircraft_seats) FROM aircrafts; +SELECT customer_status, AVG(total_customer_mileage) +FROM customers +GROUP BY customer_status; +SELECT COUNT(*) FROM aircrafts +WHERE aircraft_model LIKE '%Boeing%'; +SELECT * FROM flights +WHERE flight_mileage BETWEEN 300 AND 2000; +SELECT c.customer_status, AVG(f.flight_mileage) +FROM bookings b + JOIN customers c ON b.customer_id = c.customer_id + JOIN flights f ON b.flight_number = f.flight_number +GROUP BY c.customer_status; +-- Nota: Usiamo aircraft_model come chiave di collegamento tra flights e aircrafts +SELECT f.aircraft_model, 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 +WHERE c.customer_status = 'Gold' +GROUP BY f.aircraft_model +ORDER BY total_bookings DESC +LIMIT 1; + + + + + + + + + diff --git a/.idea/lab-java-normalization-ddl-aggregation.iml b/.idea/lab-java-normalization-ddl-aggregation.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-normalization-ddl-aggregation.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3653b1f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..152076a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..b896750 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file