Trinh Tong 5 anni fa
parent
commit
9023cec528
1 ha cambiato i file con 21 aggiunte e 3 eliminazioni
  1. 21
    3
      pokemon_sql/pokepart3.sql

+ 21
- 3
pokemon_sql/pokepart3.sql Vedi File

@@ -53,13 +53,31 @@ GROUP BY ty.name;
53 53
 # count num of trainers
54 54
 # pokelevel = 100
55 55
 
56
+# get trainer ID
57
+# counting the pokemon level where =plevel = 100 group by trainerID
58
+SELECT pt.trainerID, count(pt.pokelevel)
59
+from pokemon.pokemon_trainer pt
60
+where (pokelevel = 100)
61
+group by (pt.trainerID);
56 62
 
57 63
 
58 64
 
59 65
 
66
+# How many pokemon only belong to one trainer and no other?
67
+# many to many
68
+# but we only want the ones with 1 pokemon
69
+# count pokemon ID
70
+SELECT count(1) from
71
+(SELECT distinct Count(pt.trainerID), pt.pokemon_id
72
+from pokemon.pokemon_trainer pt
73
+#count the pokemon with distinct trainer ID
74
+#group by is what the count/sum/avg etc is working on
75
+GROUP BY pt.pokemon_id
76
+having Count(*) = 1) pokemons
77
+
78
+# look for trainers who only have 1 pokemon that no other trainers have
79
+
80
+
60 81
 
61 82
 
62 83
 
63
-# How many pokemon only belong to one trainer and no other?
64
-SELECT count(distinct pt.trainerID)
65
-from pokemon.pokemon_trainer pt;