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.
Binary file added answers/.DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions answers/Part 2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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 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(*) FROM pokemons;

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

# Question: How many pokemon have a secondary type?
# Answer: 316
SELECT COUNT(secondary_type) FROM pokemons;
24 changes: 24 additions & 0 deletions answers/Part 3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Question: What is each pokemon's primary type?
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(secondary_type) 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?
SELECT t.name, COUNT(primary_type) 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? (Hint: your query should not display a trainer
SELECT DISTINCT(t.trainername), COUNT(pokelevel) FROM pokemon_trainer pt JOIN trainers t ON pt.trainerID = t.trainerID WHERE pokelevel = 100 GROUP BY pt.trainerID;

# Question: How many pokemon only belong to one trainer and no other?
# Answer: 13
SELECT COUNT(pokemon_id), p.name FROM pokemon_trainer pt JOIN pokemons p ON pt.pokemon_id = p.id GROUP BY pokemon_id HAVING COUNT(pokemon_id) = 1;
11 changes: 11 additions & 0 deletions answers/Part 4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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;
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');