|
@@ -0,0 +1,45 @@
|
|
1
|
+### PART 3 ###
|
|
2
|
+#each pokemons primary type
|
|
3
|
+SELECT p.name, pt.name
|
|
4
|
+FROM pokemon.pokemons p
|
|
5
|
+JOIN pokemon.types pt
|
|
6
|
+ON pt.id = p.primary_type;
|
|
7
|
+
|
|
8
|
+#What is Rufflet's secondary type
|
|
9
|
+SELECT p.name, t.name
|
|
10
|
+FROM pokemon.pokemons p
|
|
11
|
+JOIN pokemon.types t
|
|
12
|
+ON p.secondary_type = t.id WHERE p.name = "rufflet";
|
|
13
|
+
|
|
14
|
+#what are the names of the pokemon that belong to the trainer with the trainerID 303?
|
|
15
|
+SELECT p.name
|
|
16
|
+FROM pokemon.pokemons p
|
|
17
|
+JOIN pokemon.pokemon_trainer ptrain
|
|
18
|
+ON ptrain.pokemon_id = p.id WHERE ptrain.trainerID = 303;
|
|
19
|
+
|
|
20
|
+#How many pokemon have a secondary type Poison
|
|
21
|
+SELECT count(p.secondary_type)
|
|
22
|
+FROM pokemon.pokemons p
|
|
23
|
+JOIN pokemon.types pt
|
|
24
|
+ON p.secondary_type = pt.id WHERE pt.name = "poison";
|
|
25
|
+
|
|
26
|
+#What are all the primary types and how many pokemon have that type?
|
|
27
|
+SELECT pt.name , count(pt.id) AS "Number of pokemon"
|
|
28
|
+FROM pokemon.pokemons p
|
|
29
|
+JOIN pokemon.types pt
|
|
30
|
+ON p.primary_type = pt.id
|
|
31
|
+GROUP BY pt.name;
|
|
32
|
+
|
|
33
|
+#how many pokemon at level 100 does each trainer with at least one level 100 pokemon have?
|
|
34
|
+#hint: your query should not display a trainer
|
|
35
|
+SELECT count(ptrain.pokelevel) AS "number of pokemon above 100 for each trainer with at least one pokemon above 100"
|
|
36
|
+FROM pokemon.pokemon_trainer ptrain
|
|
37
|
+WHERE ptrain.pokelevel = 100
|
|
38
|
+GROUP BY ptrain.trainerID;
|
|
39
|
+
|
|
40
|
+#how many pokemon only belong to one trainer and no other?
|
|
41
|
+SELECT COUNT(*) as "UniquelyOwned"
|
|
42
|
+FROM (SELECT DISTINCT pokemon_id, COUNT(pokemon_id)
|
|
43
|
+ FROM pokemon.pokemon_trainer
|
|
44
|
+ GROUP BY pokemon_id
|
|
45
|
+ HAVING COUNT(DISTINCT trainerID) = 1) alias;
|