|
@@ -22,23 +22,83 @@ From here you should have all the pokemon data in your mysql schema. Feel free t
|
22
|
22
|
Directions: Write a sql query or sql queries that can answer the following questions
|
23
|
23
|
|
24
|
24
|
* What are all the types of pokemon that a pokemon can have?
|
|
25
|
+
|
|
26
|
+ SELECT COUNT(id) FROM pokemon.types;
|
|
27
|
+
|
25
|
28
|
* What is the name of the pokemon with id 45?
|
|
29
|
+
|
|
30
|
+ SELECT name FROM pokemon.pokemons WHERE id = 45;
|
|
31
|
+
|
26
|
32
|
* How many pokemon are there?
|
|
33
|
+
|
|
34
|
+ SELECT COUNT(id) FROM pokemon.pokemons;
|
|
35
|
+
|
27
|
36
|
* How many types are there?
|
|
37
|
+
|
28
|
38
|
* How many pokemon have a secondary type?
|
29
|
39
|
|
|
40
|
+ SELECT COUNT(id) FROM pokemon.pokemons WHERE secondary_type IS NOT NULL;
|
30
|
41
|
### Part 3: Joins and Groups
|
31
|
42
|
Directions: Write a sql query or sql queries that can answer the following questions
|
32
|
43
|
|
33
|
44
|
|
34
|
45
|
* What is each pokemon's primary type?
|
|
46
|
+
|
|
47
|
+ SELECT pokemon.pokemons.name, pokemon.types.name
|
|
48
|
+ FROM pokemon.pokemons
|
|
49
|
+ JOIN pokemon.types ON pokemons.primary_type = types.id;
|
|
50
|
+
|
35
|
51
|
* What is Rufflet's secondary type?
|
|
52
|
+
|
|
53
|
+ SELECT pokemons.name, pokemons.secondary_type, types.name
|
|
54
|
+ FROM pokemon.pokemons
|
|
55
|
+ JOIN pokemon.types
|
|
56
|
+ ON pokemons.secondary_type = types.id
|
|
57
|
+ WHERE pokemons.name = "Rufflet";
|
|
58
|
+
|
36
|
59
|
* What are the names of the pokemon that belong to the trainer with trainerID 303?
|
|
60
|
+
|
|
61
|
+ SELECT pokemons.name FROM pokemon.pokemons
|
|
62
|
+ JOIN pokemon.pokemon_trainer
|
|
63
|
+ ON pokemons.id = pokemon_trainer.pokemon_id
|
|
64
|
+ WHERE pokemon_trainer.trainerID = 303;
|
|
65
|
+
|
37
|
66
|
* How many pokemon have a secondary type `Poison`
|
|
67
|
+
|
|
68
|
+ SELECT pokemon.types.name, COUNT(pokemon.pokemons.name) AS "Count - Type Poison"
|
|
69
|
+ FROM pokemon.pokemons
|
|
70
|
+ JOIN pokemon.types
|
|
71
|
+ ON pokemon.pokemons.secondary_type = pokemon.types.id
|
|
72
|
+ WHERE pokemon.types.name = "Poison";
|
|
73
|
+
|
38
|
74
|
* What are all the primary types and how many pokemon have that type?
|
|
75
|
+
|
|
76
|
+ SELECT pokemon.types.name, COUNT(pokemon.pokemons.name) AS "Count"
|
|
77
|
+ FROM pokemon.pokemons
|
|
78
|
+ JOIN pokemon.types
|
|
79
|
+ ON pokemons.primary_type = types.id
|
|
80
|
+ GROUP BY pokemon.types.id;
|
|
81
|
+
|
39
|
82
|
* 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
|
40
|
|
-* How many pokemon only belong to one trainer and no other?
|
41
|
83
|
|
|
84
|
+ SELECT COUNT(pokemon_trainer.pokemon_id)
|
|
85
|
+ FROM pokemon.pokemon_trainer
|
|
86
|
+ WHERE pokemon.pokemon_trainer.pokelevel = 100;
|
|
87
|
+
|
|
88
|
+Not sure how to answer the "each" part of the question without showing trainers. So below is an alternative response that shows "each" trainer by trainerID.
|
|
89
|
+
|
|
90
|
+ SELECT COUNT(pokemon_trainer.pokemon_id)
|
|
91
|
+ FROM pokemon.pokemon_trainer
|
|
92
|
+ WHERE pokemon.pokemon_trainer.pokelevel = 100
|
|
93
|
+ GROUP BY pokemon_trainer.trainerID;
|
|
94
|
+
|
|
95
|
+* How many pokemon only belong to one trainer and no other?
|
|
96
|
+ * the answer is 0.
|
|
97
|
+
|
|
98
|
+ SELECT COUNT(pokemon.pokemon_trainer.pokemon_id)
|
|
99
|
+ FROM pokemon.pokemon_trainer
|
|
100
|
+ HAVING COUNT(pokemon_trainer.trainerID) = 1;
|
|
101
|
+
|
42
|
102
|
### Part 4: Final Report
|
43
|
103
|
|
44
|
104
|
Directions: Write a query that returns the following collumns:
|