Skip to content
Open

two #32

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.
19 changes: 19 additions & 0 deletions answers/Part2.sql .sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 1.What are all the types of pokemon that a pokemon can have?
SELECT * FROM types;

# 2.What is the name of the pokemon with id 45?
-- Eevve
SELECT * FROM Pokemons WHERE id = 45;

# 3.How many pokemon are there?
-- 656
SELECT COUNT(*) FROM pokemons;

# 4. How many types are there?
-- 18
SELECT COUNT(*) FROM types;

# 5. How many pokemon have a secondary type?
-- 316
SELECT COUNT(secondary_type) FROM pokemons;

66 changes: 66 additions & 0 deletions answers/Part3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#1 What is each pokemon's primary type?
--
SELECT
p.name AS Pokemon_Name,
t.name AS Primary_Type_Name
FROM Pokemons p
LEFT JOIN types t
ON p.primary_type = t.id;

#2 What is Rufflet's secondary type?
-- normal
SELECT
p.name AS Pokemon_Name,
t.name AS Primary_Type_Name
FROM Pokemons p
LEFT JOIN types t
ON p.primary_type = t.id
WHERE p.name = "Rufflet";

#3 What are the names of the pokemon that belong to the trainer with trainerID 303?
-- | Wailord y Vileplum
SELECT
name AS Pokemon_Name
FROM Pokemons p
WHERE EXISTS (SELECT 1 FROM pokemon_trainer pt WHERE pt.trainerID = 303 AND pt.pokemon_id = p.id);

#4 How many pokemon have a secondary type `Poison`
-- 31

SELECT COUNT(secondary_type) FROM pokemons p JOIN types t ON p.secondary_type = t.id WHERE t.name = 'Poison';

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

#6 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
trainerid,
COUNT(1) AS Count_Pokemon_Lvl100
FROM Pokemon_trainer
WHERE pokelevel = 100
GROUP BY trainerID;

#7 How many pokemon only belong to one trainer and no other?
-- 13
SELECT
COUNT(pokemon_id) AS COUNT
FROM (
SELECT
pokemon_id,
COUNT(trainerID) AS Count_One_Trainer
FROM pokemon_trainer
GROUP BY pokemon_id
HAVING Count_One_Trainer = 1
) x;

--------------------------- to see the names ----------------------
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;
17 changes: 17 additions & 0 deletions answers/Part4sql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- return these columns --- Pokemon's name| Trainer's name| Current Level| Primary Type Name| Secondary Type Name|
-- Sort the data by finding out which trainer has the strongest pokemon -- strongest to weakest

select pokemons_name, trainers_name, current_level, primary_type_name, types.name as secondary_type_name
from (select pokemons.name as pokemons_name, trainers.trainername as trainers_name, pokemon_trainer.pokelevel as current_level, types.name as primary_type_name, pokemons.secondary_type as secondary_type_id
from pokemons
join pokemon_trainer on pokemon_trainer.pokemon_id = pokemons.id
join trainers on trainers.trainerid = pokemon_trainer.trainerid
join types on types.id = pokemons.primary_type) table_1
join types on types.id = secondary_type_id
order by current_level desc;





-- It has the strongest levels----------
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');