A sql lab filled with pokemon data

Part4 1.1KB

1234567891011121314151617
  1. Sort the data by finding out which trainer has the strongest pokemon so that this will act as a ranking of strongest to weakest trainer. You may interpret strongest in whatever way you want, but you will have to explain your decision.
  2. Explanation::
  3. I sorted by average pokemon level of each trainers. Then trainers with the same level, I sorted by who has the most pokemon. Following that, i sorted in alphabetical order.
  4. SELECT ANY_VALUE(pokemon.pokemons.name),
  5. pokemon.trainers.trainername,
  6. ANY_VALUE(pokemon.pokemon_trainer.pokelevel),
  7. ANY_VALUE(type1.name),
  8. ANY_VALUE(type2.name)
  9. FROM pokemon.pokemons
  10. CROSS JOIN pokemon.pokemon_trainer ON pokemon.pokemons.id = pokemon.pokemon_trainer.pokemon_id
  11. CROSS JOIN pokemon.trainers ON pokemon.trainers.trainerID = pokemon.pokemon_trainer.trainerID
  12. LEFT JOIN pokemon.types AS type1 ON pokemon.pokemons.primary_type = type1.id
  13. LEFT JOIN pokemon.types AS type2 ON pokemon.pokemons.secondary_type = type2.id
  14. GROUP BY pokemon.trainers.trainername
  15. ORDER BY AVG(pokemon.pokemon_trainer.pokelevel) DESC, COUNT(pokemon.trainers.trainername) DESC, pokemon.trainers.trainername