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.
52 changes: 52 additions & 0 deletions answers/answers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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(*) 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;
SELECT COUNT(secondary_type) From pokemons;

# What is each pokemon's primary type?
SELECT p.name , t.name FROM pokemons p JOIN types t ON p.primary_type = t.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 trainerID 303?
SELECT p.name, pt.trainerID FROM pokemons p JOIN pokemon_trainer pt ON p.id = pt.pokemon_ID WHERE pt.trainerID = 303;

# How many pokemon have a secondary type Poison
SELECT COUNT(secondary_type) FROM pokemons WHERE secondary_type = 7;

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

# How many pokemon at level 100 does each trainer with at least one level 100 pokemone have?
SELECT pt.trainerID, COUNT(*) FROM pokemon_trainer pt WHERE pt.pokelevel = 100 GROUP BY pt.trainerID;

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


# 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.
SELECT p.name AS 'Pokemon Name',
tr.trainername AS 'Trainer Name',
pt.pokelevel AS 'Level',
tp.name AS 'Primary Type',
tp2.name AS 'Secondary Type'
FROM pokemon_trainer pt
JOIN trainers tr ON pt.trainerID = tr.trainerID
JOIN pokemons p ON pt.pokemon_id = p.id
JOIN types tp ON p.primary_type = tp.id
JOIN types tp2 ON p.secondary_type = tp2.id
ORDER BY (spatk + speed + maxhp) DESC, pt.pokelevel DESC;

# Sorted by highest level as well as the most special attack, the highest speed, and the most HP for a quick strike with power!
Empty file removed answers/answers.txt
Empty file.
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');