Connor Dunnigan před 6 roky
rodič
revize
81dfa4f4f6
5 změnil soubory, kde provedl 113 přidání a 0 odebrání
  1. 19
    0
      .idea/dataSources.xml
  2. 6
    0
      .idea/vcs.xml
  3. 20
    0
      Queries/part2.md
  4. 48
    0
      Queries/part3.md
  5. 20
    0
      Queries/part4.md

+ 19
- 0
.idea/dataSources.xml Zobrazit soubor

@@ -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="5779d317-fa56-421f-8d79-cc1566eca717">
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>

+ 6
- 0
.idea/vcs.xml Zobrazit soubor

@@ -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>

+ 20
- 0
Queries/part2.md Zobrazit soubor

@@ -0,0 +1,20 @@
1
+#Part 1: Importing data
2
+CREATE SCHEMA pokemon;
3
+
4
+
5
+#Part 2: Simple Selects and Counts
6
+
7
+## What are all the types of pokemon that a pokemon can have?
8
+SELECT name FROM pokemon.types;
9
+
10
+## What is the name of the pokemon with id 45?
11
+SELECT name FROM pokemon.pokemons WHERE pokemons.id = 45;
12
+
13
+## How many pokemon are there?
14
+SELECT COUNT(*) AS "All Pokemon" FROM pokemon.pokemons;
15
+
16
+## How many types are there?
17
+SELECT COUNT(*) FROM pokemon.types;
18
+
19
+## How many pokemon have a secondary type?
20
+SELECT COUNT(secondary_type) FROM pokemon.pokemons;

+ 48
- 0
Queries/part3.md Zobrazit soubor

@@ -0,0 +1,48 @@
1
+#Part 3: Joins and Groups
2
+
3
+## What is each pokemon's primary type?
4
+SELECT pok.name, t.name FROM pokemon.pokemons pok
5
+JOIN pokemon.types t ON pok.primary_type = t.id;
6
+
7
+## What is Rufflet's secondary type?
8
+SELECT pok.name, t.name FROM pokemon.pokemons pok
9
+JOIN pokemon.types t
10
+        ON pok.secondary_type = t.id
11
+WHERE pok.name = "Rufflet";
12
+
13
+## What are the names of the pokemon that belong to the trainer with trainerID 303?
14
+SELECT trainer.trainername AS "Trainer", GROUP_CONCAT(pok.name) AS "Pokemons"
15
+FROM pokemon.pokemons pok
16
+JOIN pokemon.pokemon_trainer pokTrainer
17
+         ON pokTrainer.pokemon_id = pok.id
18
+JOIN pokemon.trainers trainer
19
+         ON pokTrainer.trainerID = trainer.trainerID
20
+WHERE trainer.trainerID = 303
21
+GROUP BY  trainer.trainername;
22
+
23
+## How many pokemon have a secondary type Poison
24
+SELECT COUNT(pok.secondary_type) AS "Poison Pokemons"
25
+FROM pokemon.pokemons pok
26
+JOIN pokemon.types types
27
+          ON pok.secondary_type = types.id
28
+WHERE types.name = "Poison";
29
+
30
+## What are all the primary types and how many pokemon have that type?
31
+SELECT type.name AS "Type", COUNT(pok.name) AS "Number of Pokemon"
32
+FROM pokemon.types type
33
+JOIN pokemon.pokemons pok
34
+         ON pok.primary_type = type.id
35
+GROUP BY type.name;
36
+
37
+## How many pokemon at level 100 does each trainer with at least one level 100 pokemon have?
38
+## (Hint: your query should not display a trainer
39
+SELECT COUNT(trainer.pokemon_id) as "Pokemon at Level 100"
40
+FROM pokemon.pokemon_trainer trainer
41
+WHERE trainer.pokelevel = 100
42
+GROUP BY trainer.trainerID;
43
+
44
+## How many pokemon only belong to one trainer and no other?
45
+SELECT COUNT(pokemon_id) AS "Pokemon with only one trainer"
46
+FROM (SELECT DISTINCT pokemon_id, COUNT(pokemon_id)
47
+FROM pokemon.pokemon_trainer
48
+GROUP BY pokemon_id HAVING COUNT(DISTINCT trainerID) = 1)alias;

+ 20
- 0
Queries/part4.md Zobrazit soubor

@@ -0,0 +1,20 @@
1
+# Part 4: Final Report
2
+SELECT pok.name AS "Pokemon",
3
+       trainer.trainername AS "Trainer",
4
+       pokTrainer.pokelevel as "Level",
5
+       pType.name AS "Primary Type",
6
+       sType.name AS "Secondary Name"
7
+FROM pokemon.trainers trainer
8
+    JOIN pokemon.pokemon_trainer pokTrainer
9
+        ON trainer.trainerID = pokTrainer.trainerID
10
+    JOIN pokemon.pokemons pok
11
+        ON pok.id = pokTrainer.pokemon_id
12
+    JOIN pokemon.types pType
13
+        ON pok.primary_type = pType.id
14
+    JOIN pokemon.types sType
15
+         ON pok.secondary_type = sType.id
16
+ORDER BY pokTrainer.pokelevel DESC,
17
+         pokTrainer.attack DESC,
18
+         pokTrainer.defense DESC,
19
+         pokTrainer.maxhp DESC,
20
+         pokTrainer.hp DESC;