#1-What are all the types of pokemon that a pokemon can have? create schema pokemon; select NAME from pokemon.types #2-What is the name of the pokemon with id 45? create schema pokemon; SELECT NAME FROM pokemon.pokemons WHERE id=45 #3-How many pokemon are there? SELECT COUNT(id) FROM pokemon.pokemons; #4-How many types are there? SELECT distinct(name) FROM pokemon.types; #5-How many pokemon have a secondary type? SELECT COUNT(*) FROM pokemon.pokemons where secondary_type is not null #6-What is each pokemon's primary type? SELECT pokemons.name as Pokemon_Name,types.name as Primary_Name from pokemon.pokemons, pokemon.types where primary_type=types.id; #7-What is Rufflet's secondary type? SELECT types.name from pokemon.pokemons, pokemon.types where secondary_type=types.id and pokemon.pokemons.name ="Rufflet"; #8-What are the names of the pokemon that belong to the trainer with trainerID 303? select pokemons.name from pokemon.pokemons, pokemon.pokemon_trainer where pokemon_trainer.pokemon_id=pokemons.id and pokemon.pokemon_trainer.trainerID=303; #9-How many pokemon have a secondary type Poison SELECT count(*) from pokemon.pokemons, pokemon.types where secondary_type=types.id and types.name="Poison"; #10-What are all the primary types and how many pokemon have that type? select types.name, count(*) from pokemon.pokemons, pokemon.types where pokemons.primary_type=types.id group by types.name; #11-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 SELECT COUNT(*),pokemon.pokemons.name FROM pokemon.pokemon_trainer, pokemon.pokemons WHERE pokemon.pokemon_trainer.pokemon_id= pokemon.pokemons.id AND pokemon.pokemon_trainer.pokelevel= 100 GROUP BY name HAVING COUNT(*) >= 1; #12-How many pokemon only belong to one trainer and no other? SELECT name, COUNT(DISTINCT pokemon.pokemon_trainer.trainerID) FROM pokemon.pokemon_trainer, pokemon.pokemons WHERE pokemon.pokemon_trainer.pokemon_id= pokemon.pokemons.id GROUP BY name HAVING COUNT(DISTINCT pokemon.pokemon_trainer.trainerID)=1; #FINAL REPORT PART 4 SELECT pokemon.pokemons.name AS Pokemon_Name,pokemon.trainers.trainername AS Trainer_Name,pokemon.pokemon_trainer.pokelevel AS Level,PT.name AS Primary_Type, ST.name AS Secondary_Type FROM pokemon.pokemon_trainer,pokemon.pokemons, pokemon.types AS PT ,pokemon.types AS ST,pokemon.trainers WHERE pokemon.pokemons.id=pokemon.pokemon_trainer.pokemon_id AND pokemon.pokemons.primary_type=PT.id AND pokemon.pokemons.secondary_type=ST.id AND pokemon.pokemon_trainer.trainerID=pokemon.trainers.trainerID ORDER BY pokelevel DESC, PT.name ASC , ST.name ASC, trainername asc ; # The strongest trainer is the one who trains pokemon of highest level and then sorted in ascending order of primary level, secondary level and the trainer name # Using above stated criterion the strongest trainer is - "Bandana Guy Kaler" as returned by above query as first record