Demetrius Murray 5 vuotta sitten
vanhempi
commit
372f14316b
8 muutettua tiedostoa jossa 193 lisäystä ja 1 poistoa
  1. 19
    0
      .idea/dataSources.xml
  2. 9
    0
      .idea/sqldialects.xml
  3. 6
    0
      .idea/vcs.xml
  4. 1
    0
      Part1
  5. 21
    0
      Part2
  6. 59
    0
      Part3
  7. 17
    0
      Part4
  8. 61
    1
      README.md

+ 19
- 0
.idea/dataSources.xml Näytä tiedosto

@@ -0,0 +1,19 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
4
+    <data-source source="LOCAL" name="@localhost" uuid="3a58a6ef-d5bc-4ae6-915f-796d28da868b">
5
+      <driver-ref>mysql</driver-ref>
6
+      <synchronize>true</synchronize>
7
+      <jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
8
+      <jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
9
+      <driver-properties>
10
+        <property name="autoReconnect" value="true" />
11
+        <property name="zeroDateTimeBehavior" value="convertToNull" />
12
+        <property name="tinyInt1isBit" value="false" />
13
+        <property name="characterEncoding" value="utf8" />
14
+        <property name="characterSetResults" value="utf8" />
15
+        <property name="yearIsDateType" value="false" />
16
+      </driver-properties>
17
+    </data-source>
18
+  </component>
19
+</project>

+ 9
- 0
.idea/sqldialects.xml Näytä tiedosto

@@ -0,0 +1,9 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="SqlDialectMappings">
4
+    <file url="file://$PROJECT_DIR$/pokemon_sql/pokemon_pokemon_trainer.sql" dialect="MySQL" />
5
+    <file url="file://$PROJECT_DIR$/pokemon_sql/pokemon_pokemons.sql" dialect="MySQL" />
6
+    <file url="file://$PROJECT_DIR$/pokemon_sql/pokemon_trainers.sql" dialect="MySQL" />
7
+    <file url="file://$PROJECT_DIR$/pokemon_sql/pokemon_types.sql" dialect="MySQL" />
8
+  </component>
9
+</project>

+ 6
- 0
.idea/vcs.xml Näytä tiedosto

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="" vcs="Git" />
5
+  </component>
6
+</project>

+ 1
- 0
Part1 Näytä tiedosto

@@ -0,0 +1 @@
1
+I connected.

+ 21
- 0
Part2 Näytä tiedosto

@@ -0,0 +1,21 @@
1
+### Part 2: Simple Selects and Counts
2
+
3
+Directions: Write a sql query or sql queries that can answer the following questions
4
+
5
+* What are all the types of pokemon that a pokemon can have?
6
+
7
+        SELECT COUNT(id) FROM pokemon.types;
8
+
9
+* What is the name of the pokemon with id 45?
10
+
11
+        SELECT name FROM pokemon.pokemons WHERE id = 45;
12
+
13
+* How many pokemon are there?
14
+
15
+        SELECT COUNT(id) FROM pokemon.pokemons;
16
+
17
+* How many types are there?
18
+
19
+* How many pokemon have a secondary type?
20
+
21
+        SELECT COUNT(id) FROM pokemon.pokemons WHERE secondary_type IS NOT NULL;

+ 59
- 0
Part3 Näytä tiedosto

@@ -0,0 +1,59 @@
1
+Directions: Write a sql query or sql queries that can answer the following questions
2
+
3
+
4
+* What is each pokemon's primary type?
5
+
6
+        SELECT pokemon.pokemons.name, pokemon.types.name
7
+        FROM pokemon.pokemons
8
+        JOIN pokemon.types ON pokemons.primary_type = types.id;
9
+
10
+* What is Rufflet's secondary type?
11
+
12
+        SELECT pokemons.name, pokemons.secondary_type, types.name
13
+        FROM pokemon.pokemons
14
+        JOIN pokemon.types
15
+        ON pokemons.secondary_type = types.id
16
+        WHERE pokemons.name = "Rufflet";
17
+
18
+* What are the names of the pokemon that belong to the trainer with trainerID 303?
19
+
20
+        SELECT pokemons.name FROM pokemon.pokemons
21
+        JOIN pokemon.pokemon_trainer
22
+        ON pokemons.id = pokemon_trainer.pokemon_id
23
+        WHERE pokemon_trainer.trainerID = 303;
24
+
25
+* How many pokemon have a secondary type `Poison`
26
+
27
+        SELECT pokemon.types.name, COUNT(pokemon.pokemons.name) AS "Count - Type Poison"
28
+        FROM pokemon.pokemons
29
+        JOIN pokemon.types
30
+        ON pokemon.pokemons.secondary_type = pokemon.types.id
31
+        WHERE pokemon.types.name = "Poison";
32
+
33
+* What are all the primary types and how many pokemon have that type?
34
+
35
+        SELECT pokemon.types.name, COUNT(pokemon.pokemons.name) AS "Count"
36
+        FROM pokemon.pokemons
37
+        JOIN pokemon.types
38
+        ON pokemons.primary_type = types.id
39
+        GROUP BY pokemon.types.id;
40
+
41
+* How many pokemon at level 100 does each trainer with at least one level 100 pokemone have? (Hint: your query should not display a trainer
42
+
43
+        SELECT COUNT(pokemon_trainer.pokemon_id)
44
+        FROM pokemon.pokemon_trainer
45
+        WHERE pokemon.pokemon_trainer.pokelevel = 100;
46
+
47
+        ...Not sure how to answer the "each" part of the question without showing trainers. So below is an alternative response that shows "each" trainer by trainerID.
48
+
49
+        SELECT COUNT(pokemon_trainer.pokemon_id)
50
+        FROM pokemon.pokemon_trainer
51
+        WHERE pokemon.pokemon_trainer.pokelevel = 100
52
+        GROUP BY pokemon_trainer.trainerID;
53
+
54
+* How many pokemon only belong to one trainer and no other?
55
+  * the answer is 0.
56
+
57
+        SELECT COUNT(pokemon.pokemon_trainer.pokemon_id)
58
+        FROM pokemon.pokemon_trainer
59
+        HAVING COUNT(pokemon_trainer.trainerID) = 1;

+ 17
- 0
Part4 Näytä tiedosto

@@ -0,0 +1,17 @@
1
+Sort the data by finding out which trainer has the strongest pokemon so that this will act as a ranking of strongest to weakest trainer. You may interpret strongest in whatever way you want, but you will have to explain your decision.
2
+
3
+Explanation::
4
+I sorted by average pokemon level of each trainers. Then trainers with the same level, I sorted by who has the most pokemon. Following that, i sorted in alphabetical order.
5
+
6
+SELECT ANY_VALUE(pokemon.pokemons.name),
7
+       pokemon.trainers.trainername,
8
+       ANY_VALUE(pokemon.pokemon_trainer.pokelevel),
9
+       ANY_VALUE(type1.name),
10
+       ANY_VALUE(type2.name)
11
+FROM pokemon.pokemons
12
+       CROSS JOIN pokemon.pokemon_trainer ON pokemon.pokemons.id = pokemon.pokemon_trainer.pokemon_id
13
+       CROSS JOIN pokemon.trainers ON pokemon.trainers.trainerID = pokemon.pokemon_trainer.trainerID
14
+       LEFT JOIN pokemon.types AS type1 ON pokemon.pokemons.primary_type = type1.id
15
+       LEFT JOIN pokemon.types AS type2 ON pokemon.pokemons.secondary_type = type2.id
16
+GROUP BY pokemon.trainers.trainername
17
+ORDER BY AVG(pokemon.pokemon_trainer.pokelevel) DESC, COUNT(pokemon.trainers.trainername) DESC, pokemon.trainers.trainername

+ 61
- 1
README.md Näytä tiedosto

@@ -22,23 +22,83 @@ From here you should have all the pokemon data in your mysql schema. Feel free t
22 22
 Directions: Write a sql query or sql queries that can answer the following questions
23 23
 
24 24
 * What are all the types of pokemon that a pokemon can have?
25
+
26
+        SELECT COUNT(id) FROM pokemon.types;
27
+        
25 28
 * What is the name of the pokemon with id 45?
29
+        
30
+        SELECT name FROM pokemon.pokemons WHERE id = 45;
31
+        
26 32
 * How many pokemon are there?
33
+
34
+        SELECT COUNT(id) FROM pokemon.pokemons;
35
+        
27 36
 * How many types are there?
37
+
28 38
 * How many pokemon have a secondary type?
29 39
 
40
+        SELECT COUNT(id) FROM pokemon.pokemons WHERE secondary_type IS NOT NULL;
30 41
 ### Part 3: Joins and Groups
31 42
 Directions: Write a sql query or sql queries that can answer the following questions
32 43
 
33 44
 
34 45
 * What is each pokemon's primary type?
46
+
47
+        SELECT pokemon.pokemons.name, pokemon.types.name
48
+        FROM pokemon.pokemons
49
+        JOIN pokemon.types ON pokemons.primary_type = types.id;
50
+        
35 51
 * What is Rufflet's secondary type?
52
+
53
+        SELECT pokemons.name, pokemons.secondary_type, types.name
54
+        FROM pokemon.pokemons
55
+        JOIN pokemon.types
56
+        ON pokemons.secondary_type = types.id
57
+        WHERE pokemons.name = "Rufflet";
58
+        
36 59
 * What are the names of the pokemon that belong to the trainer with trainerID 303?
60
+
61
+        SELECT pokemons.name FROM pokemon.pokemons
62
+        JOIN pokemon.pokemon_trainer
63
+        ON pokemons.id = pokemon_trainer.pokemon_id
64
+        WHERE pokemon_trainer.trainerID = 303;
65
+        
37 66
 * How many pokemon have a secondary type `Poison`
67
+
68
+        SELECT pokemon.types.name, COUNT(pokemon.pokemons.name) AS "Count - Type Poison"
69
+        FROM pokemon.pokemons
70
+        JOIN pokemon.types
71
+        ON pokemon.pokemons.secondary_type = pokemon.types.id
72
+        WHERE pokemon.types.name = "Poison";
73
+                
38 74
 * What are all the primary types and how many pokemon have that type?
75
+
76
+        SELECT pokemon.types.name, COUNT(pokemon.pokemons.name) AS "Count"
77
+        FROM pokemon.pokemons
78
+        JOIN pokemon.types
79
+        ON pokemons.primary_type = types.id
80
+        GROUP BY pokemon.types.id;
81
+        
39 82
 * How many pokemon at level 100 does each trainer with at least one level 100 pokemone have? (Hint: your query should not display a trainer
40
-* How many pokemon only belong to one trainer and no other?
41 83
 
84
+        SELECT COUNT(pokemon_trainer.pokemon_id)
85
+        FROM pokemon.pokemon_trainer
86
+        WHERE pokemon.pokemon_trainer.pokelevel = 100;
87
+        
88
+Not sure how to answer the "each" part of the question without showing trainers. So below is an alternative response that shows "each" trainer by trainerID.
89
+
90
+        SELECT COUNT(pokemon_trainer.pokemon_id)
91
+        FROM pokemon.pokemon_trainer
92
+        WHERE pokemon.pokemon_trainer.pokelevel = 100
93
+        GROUP BY pokemon_trainer.trainerID;
94
+        
95
+* How many pokemon only belong to one trainer and no other?
96
+  * the answer is 0.
97
+ 
98
+        SELECT COUNT(pokemon.pokemon_trainer.pokemon_id)
99
+        FROM pokemon.pokemon_trainer
100
+        HAVING COUNT(pokemon_trainer.trainerID) = 1;
101
+        
42 102
 ### Part 4: Final Report
43 103
 
44 104
 Directions: Write a query that returns the following collumns: