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.
1 change: 1 addition & 0 deletions answers/part1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE SCHEMA pokemon;
17 changes: 17 additions & 0 deletions answers/part2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# What are all the types of pokemon that a pokemon can have
USE pokemon;
SELECT * 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(*) FROM pokemons;

#How many types are there?
SELECT COUNT(*) FROM types;

# How many pokemon have a secondary type
SELECT COUNT(*) FROM pokemons
WHERE secondary_type IS NOT NULL;
46 changes: 46 additions & 0 deletions answers/part3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# What is each pokemons primary type
SELECT pokemons.name, types.name AS power1
FROM pokemon.pokemons
INNER JOIN pokemon.types
ON pokemons.primary_type = types.id;

#What is Rufflet's secondary type
SELECT p.name, t.name
FROM pokemons p
JOIN types t
ON p.secondary_type = t.id
WHERE p.name = 'Rufflet';

# What are the names of the pokemon that belong to the trainer with ID 303
SELECT ptr.trainerID, p.name
FROM pokemon_trainer ptr
JOIN pokemons p
ON p.id = ptr.pokemon_id
WHERE ptr.trainerID = 303;

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

# What are all the primary types and how many pokemon have that type
SELECT t.name, COUNT(*)
FROM types t
JOIN pokemons p
ON p.primary_type = t.id
GROUP BY t.name;

# How many pokemon at level 100 does each trainer with more than 1 level 100 have
SELECT ptr.pokelevel, COUNT(*)
FROM pokemon_trainer ptr
JOIN pokemons p
ON p.id = ptr.pokemon_id
GROUP BY ptr.trainerID, ptr.pokelevel
HAVING ptr.pokelevel = 100;

# How many pokemon only belong to one trainer and no other
SELECT p.name, COUNT(*) FROM pokemon_trainer ptr JOIN pokemons p ON p.id = ptr.pokemon_id GROUP BY p.name HAVING COUNT(*)= 1;
SELECT COUNT(pokemon_id),p.name FROM pokemon_trainer ptr JOIN pokemons p ON p.id = ptr.pokemon_id GROUP BY pokemon_id HAVING COUNT(pokemon_id)=1;

8 changes: 8 additions & 0 deletions answers/part4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Final Report , query sorted by trainer with highest pokemon level
SELECT p.name PokemonName , tr.trainername , ptr.pokelevel Level , t.name PrimaryType , ty.name SecondaryType
FROM pokemons p
JOIN pokemon_trainer ptr ON p.id = pokemon_id
JOIN trainers tr ON tr.trainerID = ptr.trainerID
LEFT JOIN types t ON p.primary_type = t.id
LEFT JOIN types ty ON p.secondary_type = ty.id
ORDER BY ptr.pokelevel DESC;
28,805 changes: 28,805 additions & 0 deletions pokemon_sql/pokemon_pokemon_trainer.sql

Large diffs are not rendered by default.

657 changes: 657 additions & 0 deletions pokemon_sql/pokemon_pokemons.sql

Large diffs are not rendered by default.

11,861 changes: 11,861 additions & 0 deletions pokemon_sql/pokemon_trainers.sql

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions pokemon_sql/pokemon_types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
create table types(id int auto_increment primary key,name text not null);
INSERT INTO pokemon.types (id, name) VALUES (1, 'Normal');
INSERT INTO pokemon.types (id, name) VALUES (2, 'Water');
INSERT INTO pokemon.types (id, name) VALUES (3, 'Grass');
INSERT INTO pokemon.types (id, name) VALUES (4, 'Rock');
INSERT INTO pokemon.types (id, name) VALUES (5, 'Fire');
INSERT INTO pokemon.types (id, name) VALUES (6, 'Ground');
INSERT INTO pokemon.types (id, name) VALUES (7, 'Poison');
INSERT INTO pokemon.types (id, name) VALUES (8, 'Bug');
INSERT INTO pokemon.types (id, name) VALUES (9, 'Electric');
INSERT INTO pokemon.types (id, name) VALUES (10, 'Dragon');
INSERT INTO pokemon.types (id, name) VALUES (11, 'Steel');
INSERT INTO pokemon.types (id, name) VALUES (12, 'Dark');
INSERT INTO pokemon.types (id, name) VALUES (13, 'Fighting');
INSERT INTO pokemon.types (id, name) VALUES (14, 'Psychic');
INSERT INTO pokemon.types (id, name) VALUES (15, 'Ghost');
INSERT INTO pokemon.types (id, name) VALUES (16, 'Fairy');
INSERT INTO pokemon.types (id, name) VALUES (17, 'Ice');
INSERT INTO pokemon.types (id, name) VALUES (18, 'Flying');