From 734d7543e2e88250d1ba81179e326e63fe52e3b3 Mon Sep 17 00:00:00 2001 From: Tazz1287 Date: Sun, 28 Sep 2025 21:52:11 +0200 Subject: [PATCH 1/2] Murad Lab6 --- .idea/.gitignore | 8 ++ .idea/Ex1 | 37 ++++++ .idea/Ex2.txt | 119 ++++++++++++++++++ ...lab-java-normalization-ddl-aggregation.iml | 9 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + 7 files changed, 193 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Ex1 create mode 100644 .idea/Ex2.txt create mode 100644 .idea/lab-java-normalization-ddl-aggregation.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Ex1 b/.idea/Ex1 new file mode 100644 index 0000000..58b5e50 --- /dev/null +++ b/.idea/Ex1 @@ -0,0 +1,37 @@ +USE EX1; + +CREATE TABLE Authors( + AuthorID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + AuthorName VARCHAR(100) +); + + +CREATE TABLE Articles( + ArticleID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + ArticleTitle VARCHAR(100), + WordCount INT, + Views INT + + + +); + +CREATE TABLE Publications +( + AritcleID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + AuthorID INT, + ArticleID INT, + FOREIGN KEY(AuthorID) REFERENCES Authors(AuthorID), + FOREIGN KEY (ArticleID) REFERENCES Articles(ArticleID) +); + +INSERT INTO Authors (AuthorName) VALUES ('Maria Charlotte'), ('Juan Perez'), ('Gemma Alcocer'); +INSERT INTO Articles (ArticleTitle,WordCount,Views) +VALUES + ( 'Best Paint Colors', 814, 14), + ( 'Small Space Decorating Tips', 1146, 221), + ('Hot Accessories', 986, 105), + ( 'Mixing Textures', 765, 22), + ('Kitchen Refresh', 1242, 307), + ('Homemade Art Hacks', 1002, 193), + ( 'Refinishing Wood Floors', 1571, 7542); diff --git a/.idea/Ex2.txt b/.idea/Ex2.txt new file mode 100644 index 0000000..a27861f --- /dev/null +++ b/.idea/Ex2.txt @@ -0,0 +1,119 @@ +Lab6 ~/IdeaProjects/Lab6 + .idea + Lab6.iml +External Libraries +Scratches and Consoles + + +CREATE DATABASE Lab_6; + +USE Lab_6; + + +CREATE TABLE Customers ( + CustomerID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + CustomerName VARCHAR(100), + CustomerStatus VARCHAR(50), + TotalCustomerMileage INT + + +); + +CREATE TABLE Aircrafts( + AircraftID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + AircraftName Varchar(50), + TotalAircraftSeats INT +); + +CREATE TABLE Flights( + FlightNumber VARCHAR(10) PRIMARY KEY, + AircraftID INT NOT NULL, + FlightMileage INT NOT NULL, + FOREIGN KEY (AircraftID) REFERENCES Aircrafts(AircraftID) +); + +CREATE TABLE Bookings( + BookingID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + CustomerID INT NOT NULL, + FlightNumber VARCHAR(10) NOT NULL, + FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID), + FOREIGN KEY (FlightNumber) REFERENCES Flights(FlightNumber) +); + +DROP TABLE Customers; + +INSERT INTO Customers (CustomerName, CustomerStatus, TotalCustomerMileage) VALUES +('Augustine Rivera', 'Siver', 115235), +('Aliana Sepulvida', 'Silver', 6008), +('Tom Jones','Gold',205767), +('Jessica James','Silver',127656), +('Ana Janco', 'Silver', 136773), +('Jeniffer Cortez','Gold', 300582), +('Sam Rio', 'None', 2653), +('Christian Janco','Silver',14642); + +INSERT INTO Aircrafts(AircraftName, TotalAircraftSeats) VALUES + ('Boeing747',400), + ('AirBusA330', 236); + +INSERT INTO Flights(FlightNumber, AircraftID, FlightMileage) VALUES + ('DL147',1,135), + ('DL122',2,4370), + ('DL53',3,135), + ('DL222',3,1765), + ('DL37',1,531); + +INSERT INTO Bookings(CustomerID, FlightNumber) VALUES + (1,'DL147'), + (1,'DL122'), + (2,'DL122'), + (1,'DL122'), + (3,'DL122'), + (3,'DL53'), + (1,'DL147'), + (7,'DL147'), + (1,'DL147'), + (3,'DL222'), + (4,'DL147'), + (7,'DL147'), + (5,'DL222'), + (6,'DL222'), + (4,'DL122'), + (7,'DL37'), + (8,'DL222'); + + + +SELECT COUNT(DISTINCT FlightNumber) FROM Flights; +SELECT AVG(FlightMileage) from FLIGHTS; +SELECT AVG(TotalAircraftSeats) FROM Aircrafts; +SELECT CustomerStatus, AVG(TotalCustomerMileage) FROM Customers GROUP BY CustomerStatus; +SELECT CustomerStatus, MAX(TotalCustomerMileage) FROM Customers GROUP BY CustomerStatus; +SELECT COUNT(*) FROM Aircrafts WHERE AircraftName LIKE '%Boeing%'; +SELECT * FROM Flights WHERE FlightMileage BETWEEN 300 and 2000; + +SELECT c.CustomerStatus, AVG(f.FlightMileage) AS AverateMileage +FROM Bookings b +JOIN Customers c ON b.CustomerID =c.CustomerID +JOIN Flights f ON b.FlightNumber = f.FlightNumber +GROUP BY c.CustomerStatus; + +UPDATE Flights +SET FlightNumber = 'DL53' +WHERE FlightNumber = '53'; + +UPDATE Customers +Set CustomerStatus = 'Silver' +WHERE CustomerStatus = 'Siver' + +SELECT a.AircraftName, COUNT(*) AS total_bookings +FROM Bookings b +JOIN Customers c ON b.CustomerID = c.CustomerID +JOIN Flights f ON b.FlightNumber = f.FlightNumber +JOIN Aircrafts a ON f.AircraftID = a.AircraftID +WHERE c.CustomerStatus = 'Gold' +GROUP BY a.AircraftName +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..a9182a4 --- /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/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 From 002b90fc8463618fd378db1ea87e80cb39666cda Mon Sep 17 00:00:00 2001 From: Tazz1287 Date: Sun, 28 Sep 2025 22:01:48 +0200 Subject: [PATCH 2/2] Murad Lab6 --- .idea/Ex1.sql | 37 +++++++++++++++ .idea/Ex2n3.sql | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 .idea/Ex1.sql create mode 100644 .idea/Ex2n3.sql diff --git a/.idea/Ex1.sql b/.idea/Ex1.sql new file mode 100644 index 0000000..8da3fba --- /dev/null +++ b/.idea/Ex1.sql @@ -0,0 +1,37 @@ +USE EX1; + +CREATE TABLE Authors( + AuthorID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + AuthorName VARCHAR(100) +); + + +CREATE TABLE Articles( + ArticleID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + ArticleTitle VARCHAR(100), + WordCount INT, + Views INT + + + +); + +CREATE TABLE Publications +( + AritcleID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + AuthorID INT, + ArticleID INT, + FOREIGN KEY(AuthorID) REFERENCES Authors(AuthorID), + FOREIGN KEY (ArticleID) REFERENCES Articles(ArticleID) +); + +INSERT INTO Authors (AuthorName) VALUES ('Maria Charlotte'), ('Juan Perez'), ('Gemma Alcocer'); +INSERT INTO Articles (ArticleTitle,WordCount,Views) +VALUES + ( 'Best Paint Colors', 814, 14), + ( 'Small Space Decorating Tips', 1146, 221), + ('Hot Accessories', 986, 105), + ( 'Mixing Textures', 765, 22), + ('Kitchen Refresh', 1242, 307), + ('Homemade Art Hacks', 1002, 193), + ( 'Refinishing Wood Floors', 1571, 7542); diff --git a/.idea/Ex2n3.sql b/.idea/Ex2n3.sql new file mode 100644 index 0000000..ad19fa3 --- /dev/null +++ b/.idea/Ex2n3.sql @@ -0,0 +1,117 @@ +Lab6 ~/IdeaProjects/Lab6 + .idea + Lab6.iml +External Libraries +Scratches and Consoles + + +CREATE DATABASE Lab_6; + +USE Lab_6; + + +CREATE TABLE Customers ( + CustomerID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + CustomerName VARCHAR(100), + CustomerStatus VARCHAR(50), + TotalCustomerMileage INT + + +); + +CREATE TABLE Aircrafts( + AircraftID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + AircraftName Varchar(50), + TotalAircraftSeats INT +); + +CREATE TABLE Flights( + FlightNumber VARCHAR(10) PRIMARY KEY, + AircraftID INT NOT NULL, + FlightMileage INT NOT NULL, + FOREIGN KEY (AircraftID) REFERENCES Aircrafts(AircraftID) +); + +CREATE TABLE Bookings( + BookingID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + CustomerID INT NOT NULL, + FlightNumber VARCHAR(10) NOT NULL, + FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID), + FOREIGN KEY (FlightNumber) REFERENCES Flights(FlightNumber) +); + +DROP TABLE Customers; + +INSERT INTO Customers (CustomerName, CustomerStatus, TotalCustomerMileage) VALUES + ('Augustine Rivera', 'Siver', 115235), + ('Aliana Sepulvida', 'Silver', 6008), + ('Tom Jones','Gold',205767), + ('Jessica James','Silver',127656), + ('Ana Janco', 'Silver', 136773), + ('Jeniffer Cortez','Gold', 300582), + ('Sam Rio', 'None', 2653), + ('Christian Janco','Silver',14642); + +INSERT INTO Aircrafts(AircraftName, TotalAircraftSeats) VALUES + ('Boeing747',400), + ('AirBusA330', 236); + +INSERT INTO Flights(FlightNumber, AircraftID, FlightMileage) VALUES + ('DL147',1,135), + ('DL122',2,4370), + ('DL53',3,135), + ('DL222',3,1765), + ('DL37',1,531); + +INSERT INTO Bookings(CustomerID, FlightNumber) VALUES + (1,'DL147'), + (1,'DL122'), + (2,'DL122'), + (1,'DL122'), + (3,'DL122'), + (3,'DL53'), + (1,'DL147'), + (7,'DL147'), + (1,'DL147'), + (3,'DL222'), + (4,'DL147'), + (7,'DL147'), + (5,'DL222'), + (6,'DL222'), + (4,'DL122'), + (7,'DL37'), + (8,'DL222'); + + + +SELECT COUNT(DISTINCT FlightNumber) FROM Flights; +SELECT AVG(FlightMileage) from FLIGHTS; +SELECT AVG(TotalAircraftSeats) FROM Aircrafts; +SELECT CustomerStatus, AVG(TotalCustomerMileage) FROM Customers GROUP BY CustomerStatus; +SELECT CustomerStatus, MAX(TotalCustomerMileage) FROM Customers GROUP BY CustomerStatus; +SELECT COUNT(*) FROM Aircrafts WHERE AircraftName LIKE '%Boeing%'; +SELECT * FROM Flights WHERE FlightMileage BETWEEN 300 and 2000; + +SELECT c.CustomerStatus, AVG(f.FlightMileage) AS AverateMileage +FROM Bookings b + JOIN Customers c ON b.CustomerID =c.CustomerID + JOIN Flights f ON b.FlightNumber = f.FlightNumber +GROUP BY c.CustomerStatus; + +UPDATE Flights +SET FlightNumber = 'DL53' +WHERE FlightNumber = '53'; + +UPDATE Customers +Set CustomerStatus = 'Silver' +WHERE CustomerStatus = 'Siver' + +SELECT a.AircraftName, COUNT(*) AS total_bookings +FROM Bookings b + JOIN Customers c ON b.CustomerID = c.CustomerID + JOIN Flights f ON b.FlightNumber = f.FlightNumber + JOIN Aircrafts a ON f.AircraftID = a.AircraftID +WHERE c.CustomerStatus = 'Gold' +GROUP BY a.AircraftName +ORDER BY total_bookings DESC + LIMIT 1;