### Simple Selects and Counts * What are all the types of pokemon that a pokemon can have? SELECT t.name FROM pokemon.types t; * What is the name of the pokemon with id 45? SELECT t.name FROM pokemon.pokemons t WHERE id=45; * How many pokemon are there? SELECT COUNT(*) as "count" FROM pokemon.pokemons; * How many types are there? SELECT COUNT(*) as "count" from pokemon.types; * How many pokemon have a secondary type? SELECT COUNT(secondary_type) as "count" from pokemon.pokemons WHERE secondary_type IS NOT NULL; ### Joins and Groups * What is each pokemon's primary type? SELECT p.name as "Pokemon", t.name as "Primary Type" 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 from pokemon.pokemons p JOIN pokemon.pokemon_trainer t ON p.id = t.pokemon_id WHERE t.trainerID=303; * How many pokemon have a secondary type `Poison`? SELECT p.name as "Pokemon", t.name as "Secondary Type" 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 as "Type", COUNT(p.id) as "PokeCount" FROM pokemon.types t JOIN pokemon.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 pokemon have? (Hint: your query should not display a trainer) SELECT COUNT(pokelevel) as "The Count" from pokemon.pokemon_trainer WHERE pokelevel>=100 GROUP BY trainerID; * How many pokemon only belong to one trainer and no other? SELECT p.name, COUNT(t.pokemon_id) as "trainer count" from pokemon.pokemon_trainer t JOIN pokemon.pokemons p ON t.pokemon_id = p.id GROUP BY pokemon_id HAVING COUNT(DISTINCT trainerID) = 1;