GithubHelp home page GithubHelp logo

airport-sql's Introduction

Project description

Using the data sets provided here https://www.kaggle.com/usdot/flight-delays please provide the DDL necessary to create tables for storing the 3 data sets.

Assuming you’ve loaded the data into 3 tables, please write SQL to answer following questions:

  • Busiest day of the week
  • Busiest airport
  • Busiest state (most flights with either an origin or destination in the state)
  • Busiest state (most flights with both an origin and destination in the state)

First Step before running:

Download the data and paste into raw_data/.

airport-sql
|---- /raw_data
|-------- /raw_data/airlines.csv
|-------- /raw_data/airports.csv
|-------- /raw_data/flights.csv

Infraestructure requirements:

  • Docker;
  • Docker-Compose;

Lifting the infraestructure:

The local infrastructure is a MySQL Server and a connected web admin.

  • To start the services with views containing the exercise answers run ./start_services_with_views.sh.
  • To start the services without views (and wait for each exercies query every time you run them) ./start_services_with_views.sh.

When you start the services using the above commands the following happens:

  • tables are created;
  • the data inserted into db;
  • (Optionally) views with the query answers of each exercise are created and results are shown.

Shuting down the infraestrucure:

To shut down the infraestructure run docker-compose down

Running the exercices SQLs:

It's possible to run the exercises SQLs using the Admin or inside the MySQL container.

Using the Admin:

With the admin is possible to do some exploration in the tables (but you probably would be better of using Workbench or MySQL Client);

  • Access http://localhost:8080 username root password example;
  • Click into "SQL command";
  • Copy and Run the desired SQL Query;

Using the MySQL container:

  • Get inside the container docker exec -it airport-sql_db_1 bash;
  • Run mysql -uroot -p domestic_flights;
  • Copy and Run the desired SQL query;

SQL Queries for each exercise:

  • Busiest day of the week = busiest_day_of_the_week.sql
  • Busiest airport = busiest_airport.sql
  • Busiest state (most flights with either an origin or destination in the state) = busiest_state.sql
  • Busiest state (most flights with both an origin and destination in the state) = busiest_state_regional_flights.sql

Example running those queries:

docker exec airport-sql_db_1 sh -c "mysql -uroot -pexample domestic_flights < sqls/exercises/busiest_day_of_week.sql"

Using the Materialized Views:

In my enviroment using Docker some queries are taking to long, so I've created Materialized Views (tables with the query result for top 10 busiest of each exerciese) when the services are started; Views for each exercise:

  • Busiest day of the week = busiest_day_of_the_week_mv
  • Busiest airport = busiest_airport_mv
  • Busiest state (most flights with either an origin or destination in the state) = busiest_state_mv_
  • Busiest state (most flights with both an origin and destination in the state) = busiest_state_regional_flights_mv

Example selecting from those views:

docker exec airport-sql_db_1 sh -c "mysql -uroot -pexample domestic_flights -e 'SELECT * FROM busiest_state_mv'"

If you want only the first one then add LIMIT 1 to the end of the SQL query.

airport-sql's People

Contributors

vplentz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.