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/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..063654e --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,17 @@ + + + + + mariadb + true + org.mariadb.jdbc.Driver + jdbc:mariadb://localhost:3306 + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/lab-java-sql.iml b/.idea/lab-java-sql.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-sql.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..e6be3f1 --- /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..c6ff727 --- /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..4c47968 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,7 @@ + + + + + + + \ 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 diff --git a/Normalize Table 1.numbers b/Normalize Table 1.numbers new file mode 100644 index 0000000..692e682 Binary files /dev/null and b/Normalize Table 1.numbers differ diff --git a/Normalize Table 2 - Flights.numbers b/Normalize Table 2 - Flights.numbers new file mode 100644 index 0000000..31e06b6 Binary files /dev/null and b/Normalize Table 2 - Flights.numbers differ diff --git a/sql-scripts/1-create-blog-tables.sql b/sql-scripts/1-create-blog-tables.sql new file mode 100644 index 0000000..8cc7eab --- /dev/null +++ b/sql-scripts/1-create-blog-tables.sql @@ -0,0 +1,18 @@ +create table authors ( + author_id int auto_increment primary key, + first_name varchar(255), + last_name varchar(255) +); + +create table posts ( + post_id int auto_increment primary key, + title varchar(255), + word_count int, + views int +); + +create table author_post ( + author_post_id int auto_increment primary key, + author_id int, + post_id int +); \ No newline at end of file diff --git a/sql-scripts/2-create-flight-tables.sql b/sql-scripts/2-create-flight-tables.sql new file mode 100644 index 0000000..ce8be25 --- /dev/null +++ b/sql-scripts/2-create-flight-tables.sql @@ -0,0 +1,26 @@ + +create table customers ( + customer_id int auto_increment primary key, + first_name varchar(255), + last_name varchar(255), + status varchar(255), + mileage int +); + + +create table flights ( + flight_id int auto_increment primary key, + flight_number varchar(255), + aircraft varchar(255), + seats int, + mileage int +); + +create table customer_flight ( + customer_flight_id int auto_increment primary key, + customer_id int, + flight_id int +); + + + diff --git a/sql-scripts/3-insert-into-blog-database.sql b/sql-scripts/3-insert-into-blog-database.sql new file mode 100644 index 0000000..ae9fae0 --- /dev/null +++ b/sql-scripts/3-insert-into-blog-database.sql @@ -0,0 +1,27 @@ + +# Insert into Authors +INSERT INTO authors (first_name, last_name) VALUES ('Maria', 'Charlotte'); + +INSERT INTO authors (first_name, last_name) VALUES ('Juan', 'Perez'); +INSERT INTO authors (first_name, last_name) VALUES ('Gemma', 'Alcocer'); + + +# Insert into Posts +INSERT INTO posts (title, word_count, 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); + + +# Insert into author_post +insert into author_post (author_id, post_id) values (1, 1), (1,3), (1,4), (1,6),(2,5),(3,7); + + + + + diff --git a/sql-scripts/4-insert-into-flight-database.sql b/sql-scripts/4-insert-into-flight-database.sql new file mode 100644 index 0000000..60baa7d --- /dev/null +++ b/sql-scripts/4-insert-into-flight-database.sql @@ -0,0 +1,39 @@ + +insert into customers (first_name, last_name, status, 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); + + +insert into flights (flight_number, aircraft, seats, mileage) values + ('DL143', 'Boeing 747', 400, 135), + ('DL122', 'Airbus A330', 236, 4370), + ('DL53', 'Boeing 777', 264, 2078), + ('DL222', 'Boeing 777', 264, 1765), + ('DL37', 'Boeing 777', 400, 531); + + + +insert into customer_flight (customer_id, flight_id) values + (1, 1), + (1, 1), + (1, 1), + (1, 1), + (1, 2), + (2, 2), + (3, 2), + (3, 3), + (3, 4), + (4, 1), + (4, 1), + (4, 5), + (5, 1), + (5, 2), + (6, 4), + (7, 4), + (8, 4); \ No newline at end of file diff --git a/sql-scripts/5-airline-scripts.sql b/sql-scripts/5-airline-scripts.sql new file mode 100644 index 0000000..eade719 --- /dev/null +++ b/sql-scripts/5-airline-scripts.sql @@ -0,0 +1,34 @@ + + +# 3. Total Flights +select count(flights.flight_number) as total_flights from flights; + +# 4. Average Flight Distance +select avg(flights.mileage) as average_distance from flights; + +# 5. Average Number of Seats +select avg(flights.seats) as average_seats from flights; + +# 6. Average Miles by Customer +select status, avg(customers.mileage) as average_mile_per_customer from customers group by status; + +# 7. Maximum Miles by Customer +select status, max(customers.mileage) as max_mile_per_customer from customers group by status; + + +# 8. Flights containing Boeing +select count(flights.flight_number) as Boeing_Flights from flights where aircraft like '%Boeing%'; + +# 9. Distance btn 300 - 2000 +select * from flights where mileage between 300 and 2000; + +# 10. Average distance by customer status +select status, avg(flights.mileage) as average_distance from customers join customer_flight on customers.customer_id = customer_flight.customer_id join flights on flights.flight_id = customer_flight.flight_id group by status; + +# 11. Gold status most booked flight +select flight_number, status, count(flight_number) as flights from customers join customer_flight on customers.customer_id = customer_flight.customer_id join flights on flights.flight_id = customer_flight.flight_id where status = 'Gold' group by flight_number order by flights desc ; + + + + +