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
Binary file added .DS_Store
Binary file not shown.
73 changes: 72 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,70 @@ From here you should have all the pokemon data in your mysql schema. Feel free t
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?
SELECT name FROM types;
* What is the name of the pokemon with id 45?
SELECT name FROM pokemons WHERE Id = 45;
* How many pokemon are there?
SELECT COUNT(id) FROM pokemons;
* How many types are there?
SELECT COUNT(name) FROM types;
* How many pokemon have a secondary type?
SELECT COUNT(id) FROM pokemons WHERE secondary_type IS NOT NULL;

### 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?
SELECT pokemons.name AS Pokemon_Name, types.name AS Primary_Type
FROM pokemons
INNER JOIN types
ON pokemons.primary_type = types.id;

* What is Rufflet's secondary type?
SELECT pokemons.name AS Pokemon_Name, types.name AS Secondary_Type
FROM pokemons
INNER JOIN types ON pokemons.secondary_type = types.id
WHERE pokemons.name LIKE 'Rufflet';
//Flying

* What are the names of the pokemon that belong to the trainer with trainerID 303?
SELECT trainerID, pokemons.name AS 'Pokemon Name'
FROM pokemon_trainer
INNER JOIN pokemons
ON pokemon_trainer.pokemon_id = pokemons.id
WHERE pokemon_trainer.trainerID
LIKE '303';

* How many pokemon have a secondary type `Poison`
SELECT COUNT(name) AS '#Pokemons With Poison Secondary' FROM pokemons WHERE secondary_type LIKE '7';

* 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
SELECT COUNT(pokemons.name) AS '# Pokemons', types.name AS 'Primary Type'
FROM pokemons
INNER JOIN types
ON pokemons.primary_type = types.id
GROUP BY pokemons.primary_type;

* How many pokemon at level 100 does each trainer with at least one level 100 pokemon have? (Hint: your query should not display a trainer)

SELECT DISTINCT(trainers.trainername) AS 'Trainers Name', COUNT(*) AS '# lvl 100 Pokemon'
FROM trainers
INNER JOIN pokemon_trainer
ON pokemon_trainer.trainerID = trainers.trainerID
WHERE pokelevel > 99
GROUP BY pokemon_trainer.trainerID
ORDER BY COUNT(*) DESC;

* How many pokemon only belong to one trainer and no other?

SELECT COUNT(*) AS '#People Who Caught This Pokemon', pokemons.name AS "Pokemon"
FROM pokemon_trainer
INNER JOIN pokemons
ON pokemon_trainer.pokemon_id = pokemons.id
GROUP BY pokemon_id
HAVING COUNT(*) = 1;

### Part 4: Final Report

Directions: Write a query that returns the following collumns:
Expand All @@ -50,6 +97,30 @@ Directions: Write a query that returns the following collumns:

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.

SELECT
DISTINCT(pokemon_trainer.pokemon_id) AS 'Pokemon Name',
pokemon_trainer.trainerID AS 'Trainer Name',
pokemon_trainer.pokelevel AS 'Level',
pokemons.primary_type AS 'Primary Type',
pokemons.secondary_type AS 'Secondary Type'
FROM pokemon_trainer
INNER JOIN pokemons
ON pokemon_trainer.pokemon_id = pokemons.id
ORDER BY pokemon_id DESC
;


SELECT
pokemon_trainer.pokemon_id AS 'Pokemon Name',
pokemon_trainer.trainerID AS 'Trainer Name',
pokemon_trainer.pokelevel AS 'Level',
pokemons.primary_type AS 'Primary Type',
pokemons.secondary_type AS 'Secondary Type'
FROM pokemon_trainer
INNER JOIN pokemons
ON pokemon_trainer.pokemon_id = pokemons.id;


## 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. The files should have the extension `.sql`
Expand Down
2 changes: 2 additions & 0 deletions answers/Q1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#What are all the types of pokemon that a pokemon can have?
SELECT name FROM types;
6 changes: 6 additions & 0 deletions answers/Q10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#What are all the primary types and how many pokemon have that type?
SELECT COUNT(pokemons.name) AS '# Pokemons', types.name AS 'Primary Type'
FROM pokemons
INNER JOIN types
ON pokemons.primary_type = types.id
GROUP BY pokemons.primary_type;
9 changes: 9 additions & 0 deletions answers/Q11.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#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 Distinct(trainers.trainername) AS 'Trainers Name', COUNT(*) AS '# lvl 100 Pokemon'
FROM trainers
INNER JOIN pokemon_trainer
ON pokemon_trainer.trainerID = trainers.trainerID
WHERE pokelevel > 99
GROUP BY pokemon_trainer.trainerID
ORDER BY COUNT(*) DESC;
8 changes: 8 additions & 0 deletions answers/Q12.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#How many pokemon only belong to one trainer and no other?

SELECT COUNT(pokemon_trainer.trainerID) AS '#People Who Caught This Pokemon', pokemons.name AS "Pokemon"
FROM pokemon_trainer
INNER JOIN pokemons
ON pokemon_trainer.pokemon_id = pokemons.id
GROUP BY pokemon_id
HAVING COUNT(pokemon_trainer.trainerID) = 1;
13 changes: 13 additions & 0 deletions answers/Q13.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SELECT p.name AS 'Pokemon Name',
t.trainername AS 'Trainer Name',
pt.pokelevel AS 'Level',
t1.name AS 'Primary Type',
t2.name AS 'Secondary Type'
FROM pokemon_trainer pt
JOIN trainers t ON pt.trainerID = t.trainerID
JOIN pokemons p ON pt.pokemon_id = p.id
JOIN types t1 ON p.primary_type = t1.id
JOIN types t2 ON p.secondary_type = t2.id
ORDER BY (maxhp + attack + defense + spatk + spdef + speed) DESC, pt.pokelevel DESC;

#The strongest is determined by having the highest of all the stats and having the highest level.
2 changes: 2 additions & 0 deletions answers/Q2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#What is the name of the pokemon with id 45?
SELECT name FROM pokemons WHERE Id = 45;
2 changes: 2 additions & 0 deletions answers/Q3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#How many pokemon are there?
SELECT COUNT(id) FROM pokemons;
2 changes: 2 additions & 0 deletions answers/Q4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#How many types are there?
SELECT COUNT(name) FROM types;
2 changes: 2 additions & 0 deletions answers/Q5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#How many pokemon have a secondary type?
SELECT COUNT(id) FROM pokemons WHERE secondary_type IS NOT NULL;
5 changes: 5 additions & 0 deletions answers/Q6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# What is each pokemon's primary type?
SELECT pokemons.name AS Pokemon_Name, types.name AS Primary_Type
FROM pokemons
INNER JOIN types
ON pokemons.primary_type = types.id;
6 changes: 6 additions & 0 deletions answers/Q7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# What is Rufflet's secondary type?
SELECT pokemons.name AS Pokemon_Name, types.name AS Secondary_Type
FROM pokemons
INNER JOIN types on pokemons.secondary_type = types.id
WHERE pokemons.name
LIKE 'Rufflet';
7 changes: 7 additions & 0 deletions answers/Q8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# What are the names of the pokemon that belong to the trainer with trainerID 303?
SELECT trainerID, pokemons.name AS 'Pokemon Name'
FROM pokemon_trainer
INNER JOIN pokemons
ON pokemon_trainer.pokemon_id = pokemons.id
WHERE pokemon_trainer.trainerID
LIKE '303';
5 changes: 5 additions & 0 deletions answers/Q9.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#How many pokemon have a secondary type `Poison`?
SELECT COUNT(name) AS '#Pokemons With Poison Secondary'
FROM pokemons
WHERE secondary_type
LIKE '7';
112 changes: 112 additions & 0 deletions answers/answers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# 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 DataGrip, [connect to your local mysql instance](https://www.jetbrains.com/help/idea/connecting-to-a-database.html#mysql)
**(for those not using DataGrip, you can execute the files in the command line, using the following syntax: ```mysql -u your_mysql_user -p < the_name_of_the_file.sql```)
* 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?
SELECT name FROM types;
* What is the name of the pokemon with id 45?
SELECT name FROM pokemons WHERE Id = 45;
* How many pokemon are there?
SELECT COUNT(id) FROM pokemons;
* How many types are there?
SELECT COUNT(name) FROM types;
* How many pokemon have a secondary type?
SELECT COUNT(id) FROM pokemons WHERE secondary_type IS NOT NULL;

### 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?
SELECT pokemons.name AS Pokemon_Name, types.name AS Primary_Type
FROM pokemons
INNER JOIN types
ON pokemons.primary_type = types.id;

* What is Rufflet's secondary type?
SELECT pokemons.name AS Pokemon_Name, types.name AS Secondary_Type
FROM pokemons
INNER JOIN types on pokemons.secondary_type = types.id WHERE pokemons.name
LIKE 'Rufflet';
//Flying

* What are the names of the pokemon that belong to the trainer with trainerID 303?
SELECT trainerID, pokemons.name AS 'Pokemon Name'
FROM pokemon_trainer
INNER JOIN pokemons
ON pokemon_trainer.pokemon_id = pokemons.id
WHERE pokemon_trainer.trainerID
LIKE '303';

* How many pokemon have a secondary type `Poison`
SELECT COUNT(name) AS '#Pokemons With Poison Secondary' FROM pokemons WHERE secondary_type LIKE '7';

* What are all the primary types and how many pokemon have that type?
SELECT COUNT(pokemons.name) AS '# Pokemons', types.name AS 'Primary Type'
FROM pokemons
INNER JOIN types
ON pokemons.primary_type = types.id
GROUP BY pokemons.primary_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)

SELECT Distinct(trainers.trainername) AS 'Trainers Name', COUNT(*) AS '# lvl 100 Pokemon'
FROM trainers
INNER JOIN pokemon_trainer
ON pokemon_trainer.trainerID = trainers.trainerID
WHERE pokelevel > 99
GROUP BY pokemon_trainer.trainerID
ORDER BY COUNT(*) DESC;

* How many pokemon only belong to one trainer and no other?

SELECT COUNT(pokemon_trainer.trainerID) AS '#People Who Caught This Pokemon', pokemons.name AS "Pokemo"
FROM pokemon_trainer
INNER JOIN pokemons
ON pokemon_trainer.pokemon_id = pokemons.id
GROUP BY pokemon_id
HAVING COUNT(pokemon_trainer.trainerID) = 1;

### 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. The files should have the extension `.sql`
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 your file by saving it in the "answers" directory and commititing it to your fork.
Loading