Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

final submission #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
17 changes: 17 additions & 0 deletions answers/Part 2.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?
SELECT *
FROM pokemon.types;
--What is the name of the pokemon with id 45?
SELECT name
FROM pokemon.pokemons
WHERE id = 45;
--How many pokemon are there?
SELECT COUNT(id) FROM pokemon.pokemons;
--How many types are there?
SELECT COUNT(DISTINCT primary_type)
FROM pokemon.pokemons;
--How many pokemon have a secondary type?
SELECT COUNT(id)
FROM pokemon.pokemons
WHERE secondary_type IS NOT NULL

36 changes: 36 additions & 0 deletions answers/Part 3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
USE pokemon;
-- What is each pokemon's primary type?
SELECT name, primary_type
FROM pokemon.pokemons;
-- What is Rufflet's secondary type?
SELECT secondary_type
FROM pokemon.pokemons
WHERE name = 'Rufflet';
-- What are the names of the pokemon that belong to the trainer with trainerID 303?
SELECT pokemon.pokemons.name
FROM pokemon.pokemon_trainer INNER JOIN pokemon.pokemons
ON pokemon_trainer.pokemon_id = pokemons.id
WHERE pokemon_trainer.trainerID = 303;
-- How many pokemon have a secondary type Poison
SELECT count(pokemon.pokemons.name)
FROM pokemon.pokemons INNER JOIN pokemon.types
ON pokemon.pokemons.secondary_type = pokemon.types.id
WHERE pokemon.types.name = 'Poison';

-- What are all the primary types and how many pokemon have that type?
SELECT pokemon.types.name, count(*)
FROM pokemon.pokemons INNER JOIN pokemon.types
ON pokemon.pokemons.primary_type = pokemon.types.id
GROUP BY pokemon.types.name;
-- How many pokemon at level 100 does each trainer with at least one level 100 pokemon have? (Hint: your query should not display a trainer
SELECT tr.trainername AS 'Trainer Name',
COUNT(*) AS '# lvl 100 Pokemon'
FROM pokemon_trainer pt INNER JOIN trainers tr on pt.trainerID = tr.trainerID
WHERE pokelevel = 100
GROUP BY pt.trainerID
ORDER BY COUNT(*) DESC;-- How many pokemon only belong to one trainer and no other?
SELECT COUNT(DISTINCT pokemon.pokemon_trainer.pokemon_id)
FROM pokemon.pokemon_trainer;



43 changes: 43 additions & 0 deletions answers/Part 4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
USE pokemon;
-- Part 4: Final Report

-- Directions: Write a query that returns the following collumns:
-- pt (pokemon trainer), p (pokemons), tr (trainers), t (types)


SELECT p.name AS 'Pokemon Name',
tr.trainername AS 'Trainer Name',
pt.pokelevel AS 'Level',
t.name AS 'Primary Type',
t.name AS 'Secondary Type'
FROM trainers tr
INNER JOIN pokemon_trainer pt ON tr.trainerID = pt.trainerID
INNER JOIN pokemons p ON pt.pokemon_id = p.id
INNER JOIN types t ON p.primary_type = t.id = 'T1'
INNER JOIN types t2 on p.secondary_type = t.id = 't2'
ORDER BY pt.pokelevel DESC;

-- 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.
-- You may interpret strongest in whatever way you want, but you will have to explain your decision.


SELECT trainername,pt.trainerID, SUM(pt.pokelevel) AS 'Total Level', AVG(attack) AS 'Avg Attack'
FROM trainers tr INNER JOIN pokemon_trainer pt on tr.trainerID = pt.trainerID
WHERE pokelevel = 100
GROUP BY trainername, pt.trainerID
ORDER BY SUM(pt.pokelevel) DESC, AVG(attack) DESC;
-- Myth Trainer Inity with trainerID 8044 has 6 pokemon who are level 100 AND has the highest average attack of 278.33.
-- therefore he (or she) has the strongest pokemon

--

-- practice statement
SELECT pokemon.pokemon_trainer.trainerID AS 'Trainer Name', count(*)
FROM pokemon.pokemon_trainer
WHERE pokemon_trainer.pokelevel > 99
GROUP BY pokemon.pokemon_trainer.trainerID
ORDER BY count(*) 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');