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

DONE #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

DONE #38

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.
27 changes: 27 additions & 0 deletions Part 2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
### Part 2: Simple Selects and Counts

Directions: Write a sql query or sql queries that can answer the following questions

* What are all the types of pokemon that a pokemon can have?

SELECT * 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(*)AS Number_of_Pokemons,secondary_type FROM pokemons GROUP BY secondary_type;

44 changes: 44 additions & 0 deletions Part 3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

### Part 3: Joins and Groups
Directions: Write a sql query or sql queries that can answer the following questions

* 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 secondary_type FROM pokemons WHERE name = "Rufflet";


* What are the names of the pokemon that belong to the trainer with trainerID 303?


SELECT p.name AS pokemon_name FROM pokemons p JOIN trainers t ON p.id=t.trainerID WHERE trainerID=303;

* How many pokemon have a secondary type `Poison`?

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


* What are all the primary types and how many pokemon have that type?

SELECT t.name,count(p.primary_type)
-> FROM types t
-> JOIN pokemons p
-> ON p.primary_type = t.id
-> GROUP BY t.name;

* 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 COUNT(pokemon_id)
-> FROM pokemon_trainer
-> WHERE pokelevel = 100
-> GROUP BY trainerID
-> HAVING COUNT(pokelevel)>1;


* How many pokemon only belong to one trainer and no other?
Binary file added answers/.DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions part 4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Part 4: Final Report

Directions: Write a query that returns the following collumns:

| Pokemon Name | Trainer Name | Level | Primary Type | Secondary Type |
|:------------:|:------------:|:-----:|:------------:|:--------------:|
| 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 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 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
28,805 changes: 28,805 additions & 0 deletions pokemon_sql/pokemon_pokemon_trainer.sql

Large diffs are not rendered by default.

Empty file.
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');