A sql lab filled with pokemon data

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. Directions: Write a sql query or sql queries that can answer the following questions
  2. * What is each pokemon's primary type?
  3. SELECT pokemon.pokemons.name, pokemon.types.name
  4. FROM pokemon.pokemons
  5. JOIN pokemon.types ON pokemons.primary_type = types.id;
  6. * What is Rufflet's secondary type?
  7. SELECT pokemons.name, pokemons.secondary_type, types.name
  8. FROM pokemon.pokemons
  9. JOIN pokemon.types
  10. ON pokemons.secondary_type = types.id
  11. WHERE pokemons.name = "Rufflet";
  12. * What are the names of the pokemon that belong to the trainer with trainerID 303?
  13. SELECT pokemons.name FROM pokemon.pokemons
  14. JOIN pokemon.pokemon_trainer
  15. ON pokemons.id = pokemon_trainer.pokemon_id
  16. WHERE pokemon_trainer.trainerID = 303;
  17. * How many pokemon have a secondary type `Poison`
  18. SELECT pokemon.types.name, COUNT(pokemon.pokemons.name) AS "Count - Type Poison"
  19. FROM pokemon.pokemons
  20. JOIN pokemon.types
  21. ON pokemon.pokemons.secondary_type = pokemon.types.id
  22. WHERE pokemon.types.name = "Poison";
  23. * What are all the primary types and how many pokemon have that type?
  24. SELECT pokemon.types.name, COUNT(pokemon.pokemons.name) AS "Count"
  25. FROM pokemon.pokemons
  26. JOIN pokemon.types
  27. ON pokemons.primary_type = types.id
  28. GROUP BY pokemon.types.id;
  29. * 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
  30. SELECT COUNT(pokemon_trainer.pokemon_id)
  31. FROM pokemon.pokemon_trainer
  32. WHERE pokemon.pokemon_trainer.pokelevel = 100;
  33. ...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.
  34. SELECT COUNT(pokemon_trainer.pokemon_id)
  35. FROM pokemon.pokemon_trainer
  36. WHERE pokemon.pokemon_trainer.pokelevel = 100
  37. GROUP BY pokemon_trainer.trainerID;
  38. * How many pokemon only belong to one trainer and no other?
  39. * the answer is 0.
  40. SELECT COUNT(pokemon.pokemon_trainer.pokemon_id)
  41. FROM pokemon.pokemon_trainer
  42. HAVING COUNT(pokemon_trainer.trainerID) = 1;