A sql lab filled with pokemon data

part3.txt 1.6KB

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