A sql lab filled with pokemon data

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