Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/runConfigurations/blog_sql.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/week6lab.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

<h1 align="center">Marco Villasmil</h1

<hr style="border:5px solid gray">


![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png)

# LAB | Java SQL
Expand Down Expand Up @@ -248,4 +253,4 @@ FULL OUTER JOIN:
git push origin <branch_name>
```

</details>
</details>
123 changes: 123 additions & 0 deletions airline.sql
Original file line number Diff line number Diff line change
@@ -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;


47 changes: 47 additions & 0 deletions blog.sql
Original file line number Diff line number Diff line change
@@ -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;