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..eb71c9e --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,17 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306 + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6f29fee --- /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..a086998 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/blog_sql.xml b/.idea/runConfigurations/blog_sql.xml new file mode 100644 index 0000000..4aec64f --- /dev/null +++ b/.idea/runConfigurations/blog_sql.xml @@ -0,0 +1,7 @@ + + + + FILE + + + \ No newline at end of file diff --git a/.idea/week6lab.iml b/.idea/week6lab.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/week6lab.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index cca8c33..cce482c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ +

Marco Villasmil

+ + ![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png) # LAB | Java SQL @@ -248,4 +253,4 @@ FULL OUTER JOIN: git push origin ``` - \ No newline at end of file + diff --git a/airline.sql b/airline.sql new file mode 100644 index 0000000..bfe4d32 --- /dev/null +++ b/airline.sql @@ -0,0 +1,123 @@ +CREATE SCHEMA airline_data; + +USE airline_data; + +-- created a new schema and chose the schema to insert the tables to + + + +-- the data needs to be devided into several tables + +-- creating an aircrafts table +CREATE TABLE aircraft( + aircraft_id INT AUTO_INCREMENT PRIMARY KEY, + aircraft_model VARCHAR(50), + total_aircraft_seats INT +); + + +-- creating a flights table +CREATE TABLE flights ( + flight_id INT AUTO_INCREMENT PRIMARY KEY, + flight_number VARCHAR(10), + flight_mileage INT +); + + +-- creating customers table +CREATE TABLE customers ( + cust_id INT AUTO_INCREMENT PRIMARY KEY, + cust_name VARCHAR(255), + cust_status VARCHAR(10), + total_cust_mileage INT, + cust_flight_number VARCHAR(10) +); + + +---- inserting data into their respective tables + + +INSERT INTO aircraft (aircraft_model, total_aircraft_seats) +VALUES + ('Boeing 747', 400), + ('Airbus A330', 236), + ('Boeing 777', 264); + +INSERT INTO flights (flight_number, flight_mileage) +VALUES + ('DL143', 135), + ('DL122', 4370), + ('DL53', 2078), + ('DL222', 1765), + ('DL37', 531); + +INSERT INTO customers (cust_name, cust_status, total_cust_mileage, cust_flight_number) +VALUES + ('Agustine Riviera', 'Silver', 115235, 'DL143'), + ('Alaina Sepulvida', 'None', 6008, 'DL122'), + ('Tom Jones', 'Gold', 205767, 'DL122'), + ('Sam Rio', 'None', 2653, 'DL143'), + ('Jessica James', 'Silver', 127656, 'DL143'), + ('Ana Janco', 'Silver', 136773, 'DL222'), + ('Jennifer Cortez', 'Gold', 300582, 'DL222'), + ('Christian Janco', 'Silver', 14642, 'DL222'); + + +-- exercises + +-- total number of flights +SELECT count(*) as total_flights +FROM flights; + + +-- average flight distance +SELECT ROUND(AVG(flight_mileage)) as avg_flight_distance +FROM flights; + + +-- average amount of seats +SELECT ROUND(AVG(total_aircraft_seats)) AS avg_amount_seats +FROM aircraft; + + + +-- average amount of flight miles per cst status group +SELECT + AVG(total_cust_mileage) AS avg_mileage, + cust_status +FROM customers +GROUP BY cust_status +ORDER BY avg_mileage DESC; + +-- max number of flight miles per cst status group +SELECT + MAX(total_cust_mileage) AS max_mileage, + cust_status +FROM customers +GROUP BY cust_status +ORDER BY max_mileage DESC; + + +-- total number of "Boeing" aircrafts +SELECT COUNT(aircraft_model) AS total_Boeing_aircrafts +FROM aircraft +WHERE aircraft_model like '%Boeing%'; + + + +-- list of flights with a distance between 300 and 2000 miles +SELECT flight_number, flight_mileage +FROM flights +WHERE flight_mileage BETWEEN 300 AND 2000; + + +--------- dont understand the wording of the problem +---- the average distance per cst group?? +SELECT + c.cust_status, + AVG(f.flight_mileage) AS average_flight_mileage +FROM customers c +JOIN flights f ON c.cust_flight_number = f.flight_number +GROUP BY c.cust_status; + + diff --git a/blog.sql b/blog.sql new file mode 100644 index 0000000..29bf834 --- /dev/null +++ b/blog.sql @@ -0,0 +1,47 @@ +CREATE SCHEMA blog_info; + +USE blog_info; + +-- created a new schema and chose the schema to insert the tables to + +CREATE TABLE blog_titles ( + blog_id INT AUTO_INCREMENT PRIMARY KEY, + author VARCHAR(50), + title VARCHAR(255), + word_count INT, + views INT +); + +INSERT INTO blog_titles (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); + + +-- displaying different information: + +-- showing everything +SELECT * +FROM blog_titles; + +-- number of views per author +SELECT author, SUM(views) AS total_views +FROM blog_titles +GROUP BY author +ORDER BY total_views DESC; + + +-- author ranking based on word count per views. "return on investment" of words and views +SELECT + author, + SUM(views) / SUM(word_count) AS return_per_views, + ROW_NUMBER() OVER (ORDER BY SUM(views) / SUM(word_count) DESC) AS author_ranking +FROM blog_titles +GROUP BY author +ORDER BY return_per_views DESC; +