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
4 changes: 4 additions & 0 deletions .idea/.gitignore

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

9 changes: 9 additions & 0 deletions .idea/DataGrip.PokemonSqlLab.iml

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

22 changes: 22 additions & 0 deletions .idea/dataSources.local.xml

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

11 changes: 11 additions & 0 deletions .idea/dataSources.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/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.

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.

25 changes: 25 additions & 0 deletions Part 2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Question: What are all the types of pokemon that a pokemon can have?
# Answer: Normal, Water, Grass, Rock, Fire, Ground, Poison, Bug, Electric, Dragon, Steel, Dark, Fighting, Psychic, Ghost, Fairy, Ice, Flying
SELECT GROUP_CONCAT(' ', name)
FROM types;

# Question: What is the name of the pokemon with id 45?
# Answer: Eevee
SELECT name
FROM pokemons
WHERE id = 45;

# Question: How many pokemon are there?
# Answer: 656
SELECT COUNT(1)
FROM pokemons;

# Question: How many types are there?
# Answer: 18
SELECT COUNT(1)
FROM types;

# Question: How many pokemon have a secondary type?
# Answer: 316
SELECT COUNT(secondary_type)
FROM pokemons;
55 changes: 55 additions & 0 deletions Part3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Question: What is each pokemon's primary type?
# Answer: Omitted for brevity
SELECT p.name, t.name
FROM pokemons p
JOIN types t
ON p.primary_type = t.id;

# Question: What is Rufflet's secondary type?
# Answer: Flying
SELECT t.name
FROM pokemons p
JOIN types t
ON p.secondary_type = t.id
WHERE p.name = 'Rufflet';

# Question: What are the names of the pokemon that belong to the trainer with trainerID 303?
# Answer: Wailord & Vileplume
SELECT p.name
FROM pokemon_trainer pt
JOIN pokemons p
ON pt.pokemon_id = p.id
WHERE pt.trainerID = 303;

# Question: How many pokemon have a secondary type Poison
# Answer: 31
SELECT COUNT(1)
FROM pokemons p
JOIN types t
ON p.secondary_type = t.id
WHERE t.name = 'Poison';

# Question: What are all the primary types and how many pokemon have that type?
# Answer: Omitted for brevity
SELECT t.name, COUNT(1)
FROM pokemons p
JOIN types t
ON p.primary_type = t.id
GROUP BY t.name;

# Question: How many pokemon at level 100 does each trainer with at least one level 100 pokemone have?
# Answer: Omitted for brevity
SELECT trainerID, COUNT(1)
FROM pokemon_trainer
WHERE pokelevel = 100
GROUP BY trainerID;

# Question: How many pokemon only belong to one trainer and no other?
# Answer: 13
SELECT COUNT(pokemon_id)
FROM (
SELECT pokemon_id
FROM pokemon_trainer
GROUP BY pokemon_id
HAVING COUNT(*) = 1
) AS ONE_OCCURRENCE
21 changes: 21 additions & 0 deletions Part4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Part 4: Final Report
# Explanation: Since pokelevel directly influences the fields HP, max HP, attack, defense, etc.,
# I thought the best way to order the trainers would be take an average of the totals of these fields
# for each of their pokemon. The "best" trainer will have pokemon with the highest average in these fields.

SELECT DISTINCT GROUP_CONCAT(p.name) as "Pokemon", tr.trainername as "Trainer",
GROUP_CONCAT(pt.pokelevel) as "PokeLevels", GROUP_CONCAT(t.name) as "Primary Types",
GROUP_CONCAT(r.name) as "Secondary Types", AVG_POINTS.total
FROM pokemon_trainer pt
JOIN (
SELECT trainerID, AVG(hp + maxhp + attack + defense + spatk + spdef + speed) as total
FROM pokemon_trainer
GROUP BY trainerID
) AS AVG_POINTS ON AVG_POINTS.trainerID = pt.trainerID
JOIN pokemons p ON p.id = pt.pokemon_id
JOIN trainers tr ON tr.trainerID = pt.trainerID
JOIN types t ON t.id = p.primary_type
JOIN types r ON r.id = p.secondary_type
GROUP BY AVG_POINTS.total, tr.trainerID, tr.trainername
ORDER BY AVG_POINTS.total DESC
LIMIT 20;