A sql lab filled with pokemon data

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #What is each pokemon's primary type?
  2. SELECT p.name, p.primary_type, 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, p.secondary_type, t.name
  8. from pokemons p
  9. join types t
  10. on p.secondary_type = t.id
  11. where p.name = 'Rufflet'
  12. 18 Flying
  13. #What are the names of the pokemon that belong to the trainer with trainerID 303?
  14. select p.name, pt.trainerID,pt.pokemon_id
  15. from pokemons p
  16. join pokemon_trainer pt
  17. on p.id = pt.pokemon_id
  18. where trainerID = 303
  19. Wailord, Vileplume
  20. #How many pokemon have a secondary type Poison
  21. SELECT COUNT(*)
  22. FROM pokemons
  23. join types
  24. on types.id = pokemons.secondary_type
  25. where types.name = 'poison'
  26. 31
  27. #What are all the primary types and how many pokemon have that type?
  28. select t.name, Count(*)
  29. from pokemons p
  30. join types t
  31. on t.id = p.primary_type
  32. group by t.name
  33. #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
  34. select pt.trainerID, count(*)
  35. from pokemon_trainer pt
  36. where pt.pokelevel =100
  37. group by pt.trainerID
  38. #How many pokemon only belong to one trainer and no other?
  39. select pt.pokemon_id, count(*)
  40. from pokemon_trainer pt
  41. group by pt.pokemon_id
  42. HAVING COUNT(*)=1