Skip to content

lab complete - sql #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.

9 changes: 9 additions & 0 deletions .idea/lab-java-sql.iml

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/sqldialects.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/vcs.xml

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

Binary file added Normalize Table 1.numbers
Binary file not shown.
Binary file added Normalize Table 2 - Flights.numbers
Binary file not shown.
18 changes: 18 additions & 0 deletions sql-scripts/1-create-blog-tables.sql
Original file line number Diff line number Diff line change
@@ -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
);
26 changes: 26 additions & 0 deletions sql-scripts/2-create-flight-tables.sql
Original file line number Diff line number Diff line change
@@ -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
);



27 changes: 27 additions & 0 deletions sql-scripts/3-insert-into-blog-database.sql
Original file line number Diff line number Diff line change
@@ -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);





39 changes: 39 additions & 0 deletions sql-scripts/4-insert-into-flight-database.sql
Original file line number Diff line number Diff line change
@@ -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);
34 changes: 34 additions & 0 deletions sql-scripts/5-airline-scripts.sql
Original file line number Diff line number Diff line change
@@ -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 ;