Giter Club home page Giter Club logo

011121-sql-checkpoint's Introduction

SQL and Relational Databases

In this checkpoint you will be exploring a Pokemon dataset that has been put into SQL tables. Pokemon are fictional creatures from the Nintendo franchise of the same name.

Some Pokemon facts that might be useful:

  • The word "pokemon" is both singular and plural. You may refer to "one pokemon" or "many pokemon".
  • Pokemon have attributes such as a name, weight, and height.
  • Pokemon have one or multiple "types". A type is something like "electric", "water", "ghost", or "normal" that indicates the abilities that pokemon may possess.
  • The humans who collect pokemon are called "trainers".

The schema of pokemon.db is as follows:

db schema

Assign your SQL queries as strings to the variables q1, q2, etc. and run the cells at the end of this section to print your results as Pandas DataFrames.

  • q1: Find all the pokemon on the "pokemon" table. Display all columns.

  • q2: Find all the rows from the "pokemon_types" table where the type_id is 3.

  • q3: Find all the rows from the "pokemon_types" table where the associated type is "water". Do so without hard-coding the id of the "water" type, using only the name.

  • q4: Find the names of all pokemon that have the "psychic" type.

  • q5: Find the average weight for each type. Order the results from highest weight to lowest weight. Display the type name next to the average weight.

  • q6: Find the names and ids of all the pokemon that have more than 1 type.

  • q7: Find the id of the type that has the most pokemon. Display type_id next to the number of pokemon having that type.

Important note on syntax: use double quotes "" when quoting strings within your query and wrap the entire query in single quotes ''.

DO NOT MODIFY THE PYTHON CODE BELOW (e.g. pd.read_sql). YOU ONLY NEED TO MODIFY THE SQL QUERY STRINGS.

# Run this cell without changes
import pandas as pd
import sqlite3
# Run this cell without changes
cnx = sqlite3.connect('data/pokemon.db')

Question 1: Find all the pokemon on the "pokemon" table. Display all columns.

# Enter appropriate SQL code within the quotes
q1 = ''
pd.read_sql(q1, cnx)

Question 2: Find all the rows from the "pokemon_types" table where the type_id is 3.

# Enter appropriate SQL code within the quotes
q2 = ''
pd.read_sql(q2, cnx)

Question 3: Find all the rows from the "pokemon_types" table where the associated type is "water". Do so without hard-coding the id of the "water" type, using only the name.

# Enter appropriate SQL code within the quotes
q3 = '''

'''
pd.read_sql(q3, cnx)

Question 4: Find the names of all pokemon that have the "psychic" type.

# Enter appropriate SQL code within the quotes
q4 = '''

'''
pd.read_sql(q4, cnx)

Question 5: Find the average weight for each type. Order the results from highest weight to lowest weight. Display the type name next to the average weight.

# Enter appropriate SQL code within the quotes
q5 = '''

'''
pd.read_sql(q5, cnx)

Question 6: Find the names and ids of all the pokemon that have more than 1 type.

# Enter appropriate SQL code within the quotes
q6 = '''

'''
pd.read_sql(q6, cnx)

Question 7: Find the id of the type that has the most pokemon. Display type_id next to the number of pokemon having that type.

# Enter appropriate SQL code within the quotes
q7 = '''

'''
pd.read_sql(q7, cnx)

011121-sql-checkpoint's People

Contributors

alexgriff avatar hoffm386 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.