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
2 changes: 2 additions & 0 deletions pokemonsqllab/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
.DS_Store
64 changes: 64 additions & 0 deletions pokemonsqllab/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# MySQL Pokemon Report Queries

### Goals
* Become proficient selecting data out of a mysql database
* Become comfortable performing a SQL join
* Be able to format SQL output as a readable report

## Instructions

### Part 1: Importing data
Directions:

* In intellij, [connect to your local mysql instance](https://www.jetbrains.com/help/idea/connecting-to-a-database.html#mysql)
* Create your pokemon schema
* Unpack the pokemon_sql.zip files
* One by one execute these files making sure to check your pokemon schema

From here you should have all the pokemon data in your mysql schema. Feel free to explore the data and perform a few select statements to see what the data looks like.

### Part 2: Simple Selects and Counts

Directions: Write a sql query or sql queries that can answer the following questions

* What are all the types of pokemon that a pokemon can have?
* What is the name of the pokemon with id 45?
* How many pokemon are there?
* How many types are there?
* How many pokemon have a secondary type?

### Part 3: Joins and Groups
Directions: Write a sql query or sql queries that can answer the following questions


* What is each pokemon's primary type?
* What is Rufflet's secondary type?
* What are the names of the pokemon that belong to the trainer with trainerID 303?
* How many pokemon have a secondary type `Poison`
* What are all the primary types and how many pokemon have that type?
* How many pokemon at level 100 does each trainer with at least one level 100 pokemone have? (Hint: your query should not display a trainer
* How many pokemon only belong to one trainer and no other?

### Part 4: Final Report

Directions: Write a query that returns the following collumns:

| Pokemon Name | Trainer Name | Level | Primary Type | Secondary Type |
|:------------:|:------------:|:-----:|:------------:|:--------------:|
| Pokemon's name| Trainer's name| Current Level| Primary Type Name| Secondary Type Name|

Sort the data by finding out which trainer has the strongest pokemon so that this will act as a ranking of strongest to weakest trainer. You may interpret strongest in whatever way you want, but you will have to explain your decision.

## Turning in this assignment

To turn in this assignment, create files for each part with at least one query for each question answered. Above each query include a comment with the question you were answering.
Example:

```SQL
# How many characters are in the string 'Hello World!'
SELECT CHAR_LENGTH('Hello World!') AS length_of_hello_world
```

For Part 4 specifically also leave a comment explaining how your query is deciding who the strongest trainer is

Once all of that is done, submit a pull request
17 changes: 17 additions & 0 deletions pokemonsqllab/pokemon_sql/final_report.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Directions: Write a query that returns the following collumns:
#Pokemon Name Trainer Name Level Primary Type Secondary Type
#Pokemon's name Trainer's name Current Level Primary Type Name Secondary Type Name
SELECT pokemons.name AS "Pokemon Name",
trainers.trainername AS "Trainer Name",
pokemon_trainer.pokelevel AS "Level",
t1.name AS "Primary Type",
t2.name AS "Secondary Type"
FROM pokemon.pokemons
JOIN pokemon.pokemon_trainer
ON pokemons.id = pokemon_trainer.pokemon_id
JOIN pokemon.trainers
ON pokemon_trainer.trainerID = trainers.trainerID
JOIN pokemon.types t1
ON pokemons.primary_type = t1.id
JOIN pokemon.types t2
ON pokemons.secondary_type = t2.id
25 changes: 25 additions & 0 deletions pokemonsqllab/pokemon_sql/joins_and_groups.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--What is each pokemon's primary type?
SELECT pokemons.name, types.name FROM pokemon.pokemons JOIN pokemon.types ON pokemons.primary_type = types.id;
--What is Rufflet's secondary type?
SELECT pokemons.name, types.name FROM pokemon.pokemons JOIN pokemon.types ON pokemons.primary_type = types.id WHERE pokemons.name = "Rufflet";
--What are the names of the pokemon that belong to the trainer with trainerID 303?
SELECT name, trainerID FROM pokemon.pokemons JOIN pokemon.pokemon_trainer ON id = pokemon_id WHERE trainerID = 303;
--How many pokemon have a secondary type Poison
SELECT COUNT(pokemons.name) FROM pokemon.pokemons JOIN pokemon.types ON pokemons.secondary_type = types.id WHERE types.name = "Poison";
--What are all the primary types and how many pokemon have that type?
SELECT types.name, COUNT(types.name) FROM pokemon.pokemons JOIN pokemon.types ON pokemons.primary_type = types.id GROUP BY types.name;
--How many pokemon at level 100 does each trainer with at least one level 100 pokemone have? (Hint: your query should not display a trainer
SELECT COUNT(pokemon_trainer.pokelevel), pokemon_trainer.trainerID, trainers.trainername
FROM pokemon.pokemon_trainer
JOIN pokemon.trainers
ON pokemon_trainer.trainerID = trainers.trainerID
WHERE pokemon_trainer.pokelevel = 100
GROUP BY pokemon_trainer.trainerID;
--How many pokemon only belong to one trainer and no other?
SELECT COUNT(pokemon_id)
FROM pokemon_trainer
WHERE pokemon_id in (
SELECT pokemon_id
FROM pokemon_trainer
GROUP BY pokemon_id
HAVING COUNT(pokemon_trainer.trainerID) = 1);
Loading