123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- Directions: Write a sql query or sql queries that can answer the following questions
-
-
- * What is each pokemon's primary type?
-
- SELECT pokemon.pokemons.name, pokemon.types.name
- FROM pokemon.pokemons
- JOIN pokemon.types ON pokemons.primary_type = types.id;
-
- * What is Rufflet's secondary type?
-
- SELECT pokemons.name, pokemons.secondary_type, types.name
- FROM pokemon.pokemons
- JOIN pokemon.types
- ON pokemons.secondary_type = types.id
- WHERE pokemons.name = "Rufflet";
-
- * What are the names of the pokemon that belong to the trainer with trainerID 303?
-
- SELECT pokemons.name FROM pokemon.pokemons
- JOIN pokemon.pokemon_trainer
- ON pokemons.id = pokemon_trainer.pokemon_id
- WHERE pokemon_trainer.trainerID = 303;
-
- * How many pokemon have a secondary type `Poison`
-
- SELECT pokemon.types.name, COUNT(pokemon.pokemons.name) AS "Count - Type Poison"
- FROM pokemon.pokemons
- 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(pokemon.pokemons.name) AS "Count"
- FROM pokemon.pokemons
- JOIN pokemon.types
- ON pokemons.primary_type = types.id
- GROUP BY pokemon.types.id;
-
- * 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_trainer.pokemon_id)
- FROM pokemon.pokemon_trainer
- WHERE pokemon.pokemon_trainer.pokelevel = 100;
-
- ...Not sure how to answer the "each" part of the question without showing trainers. So below is an alternative response that shows "each" trainer by trainerID.
-
- SELECT COUNT(pokemon_trainer.pokemon_id)
- FROM pokemon.pokemon_trainer
- WHERE pokemon.pokemon_trainer.pokelevel = 100
- GROUP BY pokemon_trainer.trainerID;
-
- * How many pokemon only belong to one trainer and no other?
- * the answer is 0.
-
- SELECT COUNT(pokemon.pokemon_trainer.pokemon_id)
- FROM pokemon.pokemon_trainer
- HAVING COUNT(pokemon_trainer.trainerID) = 1;
|