A sql lab filled with pokemon data

part3.sql 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  1. #What is each pokemon's primary type?'#
  2. SELECT pokemons.name, types.name
  3. FROM pokemon.pokemons JOIN pokemon.types
  4. ON pokemons.primary_type = types.id;
  5. #What is Rufflet's secondary type'#
  6. SELECT pokemons.name, types.name
  7. FROM pokemon.pokemons JOIN pokemon.types
  8. ON secondary_type = types.id
  9. WHERE pokemons.name LIKE ("Rufflet%");
  10. #What are the names of the pokemon that belong to the trainer with trainerID 303?#
  11. SELECT name, pokemon_id, trainerID
  12. FROM pokemon.pokemons JOIN pokemon.pokemon_trainer
  13. on id = pokemon_id
  14. WHERE trainerID = 303;
  15. #How many pokemon have a secondary type Poison#
  16. SELECT COUNT(id) FROM pokemon.pokemons
  17. WHERE secondary_type = 7;
  18. #What are all the primary types and how many pokemon have that type?#
  19. SELECT types.name, COUNT(primary_type) FROM pokemon.types JOIN pokemon.pokemons
  20. ON types.id = primary_type
  21. GROUP BY types.name;
  22. #How many pokemon at level 100 does each trainer with at least one level 100 pokemone have?#
  23. SELECT trainerID, COUNT(pokemon_id)
  24. FROM pokemon.pokemon_trainer
  25. WHERE pokelevel = 100
  26. GROUP BY trainerID;
  27. #How many pokemon only belong to one trainer and no other?#
  28. SELECT pokemon_id, COUNT(pokemon_id)
  29. FROM pokemon.pokemon_trainer;