A sql lab filled with pokemon data

Answers.rtf 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600
  2. {\fonttbl\f0\fswiss\fcharset0 Helvetica;}
  3. {\colortbl;\red255\green255\blue255;}
  4. {\*\expandedcolortbl;;}
  5. \margl1440\margr1440\vieww14220\viewh11000\viewkind0
  6. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
  7. \f0\fs24 \cf0 Part 2:\
  8. \
  9. What are all the types of pokemon that a pokemon can have?\
  10. \b SELECT name FROM types;\
  11. \
  12. \b0 What is the name of the pokemon with id 45?\
  13. \b SELECT name FROM pokemons WHERE id=45;
  14. \b0 \
  15. \
  16. How many pokemon are there?\
  17. \b SELECT COUNT(id) from pokemons;
  18. \b0 \
  19. \
  20. How many types are there?\
  21. \b SELECT COUNT(id) from types;
  22. \b0 \
  23. \
  24. How many pokemon have a secondary type?\
  25. \b SELECT COUNT(secondary_type) FROM pokemons;
  26. \b0 \
  27. \
  28. \
  29. Part 3:\
  30. \
  31. What is each pokemon's primary type?\
  32. \b SELECT pokemons.name, types.name FROM pokemons INNER JOIN types ON pokemons.primary_type=types.id;
  33. \b0 \
  34. \
  35. What is Rufflet's secondary type?\
  36. \b SELECT pokemons.name, types.name FROM pokemons INNER JOIN types ON pokemons.primary_type=types.id WHERE pokemons.name='Rufflet';
  37. \b0 \
  38. \
  39. What are the names of the pokemon that belong to the trainer with trainerID 303?\
  40. \b SELECT pokemons.name FROM pokemons INNER JOIN pokemon_trainer ON pokemon_trainer.pokemon_id=pokemons.id WHERE trainerID=303;
  41. \b0 \
  42. \
  43. How many pokemon have a secondary type Poison\
  44. \b SELECT COUNT(secondary_type) FROM pokemons INNER JOIN types ON pokemons.secondary_type=types.id WHERE types.name='poison';
  45. \b0 \
  46. \
  47. What are all the primary types and how many pokemon have that type?\
  48. \b SELECT COUNT(pokemons.primary_type) FROM pokemons JOIN types ON pokemons.primary_type=types.id GROUP BY types.name;
  49. \b0 \
  50. [[[Can only get the counts to display in order by name, but does not display names of Types. having trouble subquerying for the names of the types]]]\
  51. \
  52. 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\
  53. \b SELECT COUNT(pokemon_trainer.pokelevel) FROM pokemon_trainer JOIN trainers ON pokemon_trainer.pokelevel=trainers.trainerID WHERE pokemon_trainer.pokelevel=100;\
  54. \
  55. \b0 How many pokemon only belong to one trainer and no other?
  56. \b \
  57. SELECT COUNT(DISTINCT pokemon_trainer.trainerID) FROM pokemon_trainer;\
  58. \
  59. \b0 Part 4 (Final Report)\
  60. \
  61. \b \
  62. }