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.
2 changes: 2 additions & 0 deletions answers/Excercise 1.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/Excercise 10.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 NumberOfPokemons, types.name AS PrimaryType
FROM pokemons
INNER JOIN types
ON pokemons.primary_type = types.id
GROUP BY pokemons.primary_type;
4 changes: 4 additions & 0 deletions answers/Excercise 11.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 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;
11 changes: 11 additions & 0 deletions answers/Excercise 12.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# How many pokemon only belong to one trainer and no other?
SELECT COUNT(pokemon_trainer.trainerID), pokemons.name
FROM pokemon_trainer
INNER JOIN pokemons
ON pokemon_trainer.pokemon_id = pokemons.id
GROUP BY pokemon_id
HAVING COUNT(pokemon_trainer.trainerID) = 1;

Select Avg(pokemon_trainer.pokelevel)
from pokemont_trainer
Group By
12 changes: 12 additions & 0 deletions answers/Excercise 13.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Adding together the stats, ordering descending so highest overall is at top
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;
2 changes: 2 additions & 0 deletions answers/Excercise 2.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/Excercise 3.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/Excercise 4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#How many types are there?
select COUNT(*) from types;
2 changes: 2 additions & 0 deletions answers/Excercise 5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#How many pokemon have a secondary type
select COUNT(*) from pokemons where secondary_type IS NOT NULL;
2 changes: 2 additions & 0 deletions answers/Excercise 6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# What is each pokemon's primary type?
select name, primary_type from pokemons;
2 changes: 2 additions & 0 deletions answers/Excercise 7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# What is Rufflet's secondary type?
select * from pokemon_trainer INNER JOIN pokemons ON trainerID = 303 and pokemon_trainer.pokemon_id = pokemons.id;
2 changes: 2 additions & 0 deletions answers/Excercise 8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#What are the names of the pokemon that belong to the trainer with trainerID 303?
select * from pokemon_trainer INNER JOIN pokemons ON trainerID = 303 and pokemon_trainer.pokemon_id = pokemons.id;
2 changes: 2 additions & 0 deletions answers/Excercise 9.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#How many pokemon have a secondary type Poison
SELECT COUNT(name) AS Poison_Type_Pokemon FROM pokemons WHERE secondary_type LIKE '7';
31 changes: 31 additions & 0 deletions answers/answers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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(*) from types;
select COUNT(*) from pokemons where secondary_type IS NOT NULL;

select name, primary_type from pokemons;
select name, secondary_type from pokemons where name = 'Rufflet';
select * from pokemon_trainer INNER JOIN pokemons ON trainerID = 303 and pokemon_trainer.pokemon_id = pokemons.id;

select count(*) from pokemons INNER JOIN types ON secondary_type = 7;

SELECT pokemons.name, types.name FROM pokemons INNER JOIN types ON pokemons.primary_type = types.id;

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;


SELECT COUNT(trainerID), pokemon_id
FROM pokemon_trainer
GROUP BY pokemon_id
HAVING COUNT(trainerID) = 1;
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');