| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- /* What is each pokemon's primary type? */
- SELECT p.name, t.name
- FROM pokemon.pokemons p
- JOIN pokemon.types t
- ON p.primary_type = t.id;
-
- /* What is Rufflet's secondary type? */
- SELECT p.name, t.name
- FROM pokemon.pokemons p
- JOIN pokemon.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, tr.trainerID
- FROM pokemon.pokemons p
- JOIN pokemon.pokemon_trainer tr ON p.id = tr.pokemon_id
- /*GROUP BY p.name, tr.trainerID*/
- WHERE trainerID = 303;
-
- /*How many pokemon have a secondary type Poison*/
- SELECT t.name,
- COUNT(p.secondary_type) as 'Poison Secondaries'
- FROM pokemon.pokemons p
- JOIN pokemon.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.id) as 'How Many'
- FROM pokemon.pokemons p
- JOIN pokemon.types t
- 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 pokemon have? (Hint: your query should not display a trainer*/
- SELECT COUNT(pokelevel) as 'Lvl 100s'
- FROM pokemon.pokemon_trainer
- WHERE pokelevel = 100
- GROUP BY trainerID;
-
- /*How many pokemon only belong to one trainer and no other?*/
- SELECT COUNT(1) FROM
- (SELECT COUNT(p.pokemon_id) as 'Poke ID'
- FROM pokemon.pokemon_trainer p
- GROUP BY p.pokemon_id
- HAVING COUNT(*) = 1) pokemon
-
|