Trinh Tong 6 år sedan
förälder
incheckning
3addeb15df
1 ändrade filer med 14 tillägg och 1 borttagningar
  1. 14
    1
      pokemon_sql/pokepart3.sql

+ 14
- 1
pokemon_sql/pokepart3.sql Visa fil

@@ -16,16 +16,25 @@ WHERE p.name = 'Rufflet';
16 16
 
17 17
 
18 18
 # What are the names of the pokemon that belong to the trainer with trainerID 303?
19
-#concat inner join
19
+# concat inner join one to many
20
+# Select is the outcome
20 21
 SELECT t.trainername as "Trainer", group_concat(p.name) as "Pokemons"
22
+# the names from pokemon.pokemons
21 23
 FROM pokemon.pokemons p
24
+    # we join to the pokemon_trainer table (so the pokmons have names with their ids
22 25
   join pokemon.pokemon_trainer pt
23 26
   on pt.pokemon_id = p.id
27
+    # Then we do the same for the trainers, to match their names to IDs
24 28
 JOIN pokemon.trainers t
25 29
 on pt.trainerID = t.trainerID
30
+# on this specific trainer
26 31
 WHERE t.trainerID = 303
32
+# group by the trainer name
27 33
 group by t.trainername;
28 34
 
35
+# pt shows ownership
36
+# using trainer and pokemon table to pull the names of the ids on the pt table
37
+
29 38
 # How many pokemon have a secondary type Poison
30 39
 SELECT
31 40
 sum(secondary_type = 7) as "Poison Type"
@@ -47,6 +56,10 @@ GROUP BY ty.name;
47 56
 
48 57
 
49 58
 
59
+
60
+
61
+
62
+
50 63
 # How many pokemon only belong to one trainer and no other?
51 64
 SELECT count(distinct pt.trainerID)
52 65
 from pokemon.pokemon_trainer pt;