A sql lab filled with pokemon data

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. Part 2: Simple Selects and Counts
  2. What are all the types of pokemon that a pokemon can have?
  3. select name
  4. from types
  5. What is the name of the pokemon with id 45?
  6. select name
  7. from pokemons
  8. where id = 45
  9. How many pokemon are there?
  10. select count(id)
  11. from pokemons
  12. How many types are there?
  13. select count(id)
  14. from types
  15. How many pokemon have a secondary type?
  16. select count(id)
  17. from pokemons
  18. where secondary_type is not null
  19. Part 3: Joins and Groups
  20. What is each pokemons primary type?
  21. select p.name, t.name
  22. from pokemons p
  23. join types t on p.primary_type = t.id;
  24. What is Rufflets secondary type?
  25. select p.name, t.name
  26. from pokemons p
  27. join types t on p.secondary_type = t.id
  28. where p.name = 'Rufflet';
  29. What are the names of the pokemon that belong to the trainer with trainerID 303?
  30. select pt.trainerID, p.name
  31. from pokemon_trainer pt
  32. join pokemons p on pt.pokemon_id = p.id
  33. where pt.trainerID = 303;
  34. How many pokemon have a secondary type Poison
  35. select count(p.secondary_type), t.name
  36. from pokemons p
  37. join types t
  38. on p.secondary_type = t.id
  39. where p.secondary_type = 7;
  40. What are all the primary types and how many pokemon have that type?
  41. select t.name, count(t.name)
  42. from pokemons p
  43. join types t
  44. on p.primary_type = t.id
  45. group by t.name;
  46. How many pokemon at level 100 does each trainer with at least one
  47. level 100 pokemonpoq have? (Hint: your query should not display a
  48. trainer
  49. select count(distinct pt.pokemon_id)
  50. from pokemon_trainer pt
  51. where pt.pokelevel > 99;
  52. How many pokemon only belong to one trainer and no other?
  53. select count(1) from
  54. (select pt.pokemon_id
  55. from pokemon_trainer pt
  56. group by pokemon_id
  57. having count(1) = 1) x
  58. Part 4: Final Report
  59. Directions: Write a query that returns the following collumns:
  60. Pokemon Name Trainer Name Level Primary Type Secondary Type
  61. Pokemons name Trainers name Current Level Primary Type Name Secondary Type Name
  62. Sort the data by finding out which trainer has the strongest pokemon so that this
  63. will act as a ranking of strongest to weakest trainer.
  64. You may interpret strongest in whatever way you want,
  65. but you will have to explain your decision.
  66. select
  67. tr.trainername as trainer,
  68. p.name as pokemon,
  69. pt.pokelevel as pokemon_level,
  70. pt.hp as hit_points,
  71. pt.attack,
  72. t.name as primary_type,
  73. t2.name as secondary_type
  74. from pokemon_trainer pt
  75. join pokemons p on pt.pokemon_id = p.id
  76. join trainers tr on pt.trainerID = tr.trainerID
  77. join types t on p.primary_type = t.id
  78. join types t2 on p.secondary_type = t2.id
  79. order by pt.attack desc, pt.hp desc;
  80. The strongest trainers have the Rayquaza pokemon, as Rayquaza has the highest hit point and the strongest attack
  81. Chaser♂ Chotle
  82. Chaser♀ Quelis
  83. Cooltrainer♂ Forgon
  84. Cooltrainer♂ Forgon
  85. Supertrainer♀ Garvon
  86. Myth Trainer Infin
  87. Chaser♂ Chotle
  88. Chaser♀ Quelis