|
@@ -0,0 +1,71 @@
|
|
1
|
+/*How many types of pokemon can a pokemon have?*/
|
|
2
|
+SELECT COUNT(*) FROM pokemon.types;
|
|
3
|
+
|
|
4
|
+/*What is the name of the pokemon with id 45?*/
|
|
5
|
+SELECT * FROM pokemon.pokemons WHERE id LIKE '45';
|
|
6
|
+
|
|
7
|
+/*How many pokemon are there?*/
|
|
8
|
+SELECT COUNT(*) FROM pokemon.pokemons;
|
|
9
|
+
|
|
10
|
+/*How many types are there?*/
|
|
11
|
+SELECT COUNT(DISTINCT primary_type) FROM pokemons;
|
|
12
|
+
|
|
13
|
+/*How many pokemon have a secondary type?*/
|
|
14
|
+SELECT COUNT(secondary_type) From pokemons;
|
|
15
|
+
|
|
16
|
+/*What is each pokemon's primary type?*/
|
|
17
|
+SELECT p.name, t.name
|
|
18
|
+FROM pokemons p
|
|
19
|
+JOIN types t
|
|
20
|
+ON p.primary_type = t.id;
|
|
21
|
+
|
|
22
|
+/*What is Rufflet's secondary type?*/
|
|
23
|
+SELECT t.name
|
|
24
|
+FROM pokemons p
|
|
25
|
+JOIN types t
|
|
26
|
+ON p.primary_type = t.id
|
|
27
|
+WHERE p.name LIKE 'Rufflet';
|
|
28
|
+
|
|
29
|
+/*What are the names of the pokemon that belong to the trainer with trainerID 303?*/
|
|
30
|
+SELECT p.name
|
|
31
|
+FROM pokemons p
|
|
32
|
+JOIN pokemon_trainer pt
|
|
33
|
+ON pt.pokemon_id=p.id
|
|
34
|
+JOIN trainers t
|
|
35
|
+ON t.trainerID=pt.trainerID
|
|
36
|
+WHERE t.trainerID = '303';
|
|
37
|
+
|
|
38
|
+/*How many pokemon have a secondary type Poison*/
|
|
39
|
+SELECT p.name
|
|
40
|
+FROM pokemons p
|
|
41
|
+JOIN types t
|
|
42
|
+ON p.secondary_type = t.id
|
|
43
|
+Where t.name = 'Poison';
|
|
44
|
+
|
|
45
|
+/*What are all the primary types and how many pokemon have that type?*/
|
|
46
|
+SELECT t.name, COUNT(p.name)
|
|
47
|
+FROM pokemons p
|
|
48
|
+JOIN types t
|
|
49
|
+ON p.primary_type = t.id
|
|
50
|
+GROUP BY p.primary_type;
|
|
51
|
+
|
|
52
|
+/*How many pokemon at level 100 does each trainer with at least one level 100 pokemon have?*/
|
|
53
|
+Select pt.trainerID, pt.pokelevel
|
|
54
|
+FROM pokemon_trainer pt
|
|
55
|
+WHERE pt.pokelevel=100
|
|
56
|
+GROUP BY pt.trainerID;
|
|
57
|
+
|
|
58
|
+/* How many pokemon only belong to one trainer and no other?*/
|
|
59
|
+Select COUNT(pokemon_id)
|
|
60
|
+FROM (
|
|
61
|
+SELECT pt.pokemon_id
|
|
62
|
+FROM pokemon_trainer pt
|
|
63
|
+GROUP BY pt.pokemon_id
|
|
64
|
+HAVING COUNT(*)=1
|
|
65
|
+ ) AS once;
|
|
66
|
+
|
|
67
|
+SELECT pokemons.name, trainers.trainername, pokemon_trainer.pokelevel, , pokemons.secondary_type
|
|
68
|
+FROM pokemons
|
|
69
|
+JOIN
|
|
70
|
+
|
|
71
|
+
|