Trinh Tong 6 years ago
parent
commit
9023cec528
1 changed files with 21 additions and 3 deletions
  1. 21
    3
      pokemon_sql/pokepart3.sql

+ 21
- 3
pokemon_sql/pokepart3.sql View File

53
 # count num of trainers
53
 # count num of trainers
54
 # pokelevel = 100
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;