ソースを参照

All parts complete

Lauren Green 5 年 前
コミット
e3b10fa0ac
共有3 個のファイルを変更した79 個の追加45 個の削除を含む
  1. 44
    45
      .idea/workspace.xml
  2. 16
    0
      Part 3: Joins & Groups.sql
  3. 19
    0
      Part 4: Final Report.sql

+ 44
- 45
.idea/workspace.xml ファイルの表示

@@ -70,33 +70,33 @@
70 70
       </usages-collector>
71 71
       <usages-collector id="statistics.file.extensions.open">
72 72
         <counts>
73
-          <entry key="Part 2: Simple Selects &amp; Counts" value="5" />
73
+          <entry key="Part 2: Simple Selects &amp; Counts" value="6" />
74 74
           <entry key="md" value="1" />
75
-          <entry key="pokemon_trainer" value="6" />
75
+          <entry key="pokemon_trainer" value="7" />
76 76
           <entry key="pokemons" value="7" />
77
-          <entry key="sql" value="10" />
77
+          <entry key="sql" value="11" />
78 78
           <entry key="trainers" value="4" />
79 79
           <entry key="types" value="3" />
80 80
         </counts>
81 81
       </usages-collector>
82 82
       <usages-collector id="statistics.file.types.open">
83 83
         <counts>
84
-          <entry key="Database Element" value="20" />
84
+          <entry key="Database Element" value="21" />
85 85
           <entry key="PLAIN_TEXT" value="1" />
86
-          <entry key="SQL" value="12" />
86
+          <entry key="SQL" value="14" />
87 87
           <entry key="Scratch" value="3" />
88 88
         </counts>
89 89
       </usages-collector>
90 90
       <usages-collector id="statistics.file.extensions.edit">
91 91
         <counts>
92 92
           <entry key="Part 2: Simple Selects &amp; Counts" value="49" />
93
-          <entry key="sql" value="1789" />
93
+          <entry key="sql" value="2566" />
94 94
         </counts>
95 95
       </usages-collector>
96 96
       <usages-collector id="statistics.file.types.edit">
97 97
         <counts>
98
-          <entry key="SQL" value="125" />
99
-          <entry key="Scratch" value="1713" />
98
+          <entry key="SQL" value="309" />
99
+          <entry key="Scratch" value="2306" />
100 100
         </counts>
101 101
       </usages-collector>
102 102
     </session>
@@ -106,35 +106,26 @@
106 106
       <file pinned="false" current-in-tab="false">
107 107
         <entry file="file://$APPLICATION_CONFIG_DIR$/consoles/db/94ae8ad0-e995-46af-8cec-36a75eeb1c90/console.sql">
108 108
           <provider selected="true" editor-type-id="text-editor">
109
-            <state relative-caret-position="15">
110
-              <caret line="1" selection-start-line="1" selection-end-line="8" selection-end-column="23" />
109
+            <state>
110
+              <caret selection-end-line="14" selection-end-column="54" />
111 111
             </state>
112 112
           </provider>
113 113
         </entry>
114 114
       </file>
115 115
       <file pinned="false" current-in-tab="false">
116
-        <entry file="file://$PROJECT_DIR$/Part 3: Joins &amp; Groups.sql">
117
-          <provider selected="true" editor-type-id="text-editor">
118
-            <state relative-caret-position="540">
119
-              <caret line="36" lean-forward="true" selection-start-line="36" selection-end-line="36" />
116
+        <entry file="das://94ae8ad0-e995-46af-8cec-36a75eeb1c90/schema/pokemon/table/pokemon_trainer">
117
+          <provider selected="true" editor-type-id="com.intellij.database.editor.DatabaseTableFileEditorProvider">
118
+            <state>
119
+              <filtering enabled="true" />
120 120
             </state>
121 121
           </provider>
122 122
         </entry>
123 123
       </file>
124 124
       <file pinned="false" current-in-tab="true">
125
-        <entry file="file://$PROJECT_DIR$/Part 2: Simple Selects &amp; Counts">
125
+        <entry file="file://$PROJECT_DIR$/Part 4: Final Report.sql">
126 126
           <provider selected="true" editor-type-id="text-editor">
127
-            <state relative-caret-position="106">
128
-              <caret line="17" column="30" lean-forward="true" selection-start-line="17" selection-start-column="30" selection-end-line="17" selection-end-column="30" />
129
-            </state>
130
-          </provider>
131
-        </entry>
132
-      </file>
133
-      <file pinned="false" current-in-tab="false">
134
-        <entry file="das://94ae8ad0-e995-46af-8cec-36a75eeb1c90/schema/pokemon/table/pokemon_trainer">
135
-          <provider selected="true" editor-type-id="com.intellij.database.editor.DatabaseTableFileEditorProvider">
136
-            <state>
137
-              <filtering enabled="true" />
127
+            <state relative-caret-position="75">
128
+              <caret line="14" column="54" selection-start-line="14" selection-start-column="54" selection-end-line="14" selection-end-column="54" />
138 129
             </state>
139 130
           </provider>
140 131
         </entry>
@@ -150,9 +141,10 @@
150 141
         <option value="$APPLICATION_CONFIG_DIR$/consoles/db/94ae8ad0-e995-46af-8cec-36a75eeb1c90/console_1.sql" />
151 142
         <option value="$PROJECT_DIR$/pokemon_sql/Part 2: Simple Selects &amp; Counts" />
152 143
         <option value="$PROJECT_DIR$/pokemon_sql/.idea/Part 3: Joins &amp; Groups.sql" />
153
-        <option value="$APPLICATION_CONFIG_DIR$/consoles/db/94ae8ad0-e995-46af-8cec-36a75eeb1c90/console.sql" />
154
-        <option value="$PROJECT_DIR$/Part 3: Joins &amp; Groups.sql" />
155 144
         <option value="$PROJECT_DIR$/Part 2: Simple Selects &amp; Counts" />
145
+        <option value="$PROJECT_DIR$/Part 3: Joins &amp; Groups.sql" />
146
+        <option value="$APPLICATION_CONFIG_DIR$/consoles/db/94ae8ad0-e995-46af-8cec-36a75eeb1c90/console.sql" />
147
+        <option value="$PROJECT_DIR$/Part 4: Final Report.sql" />
156 148
       </list>
157 149
     </option>
158 150
   </component>
@@ -163,8 +155,8 @@
163 155
     <sorting>DEFINITION_ORDER</sorting>
164 156
   </component>
165 157
   <component name="ProjectFrameBounds">
166
-    <option name="x" value="45" />
167
-    <option name="y" value="49" />
158
+    <option name="x" value="28" />
159
+    <option name="y" value="23" />
168 160
     <option name="width" value="1280" />
169 161
     <option name="height" value="709" />
170 162
   </component>
@@ -247,10 +239,10 @@
247 239
     <option name="totallyTimeSpent" value="390000" />
248 240
   </component>
249 241
   <component name="ToolWindowManager">
250
-    <frame x="45" y="49" width="1280" height="709" extended-state="0" />
242
+    <frame x="28" y="23" width="1280" height="709" extended-state="0" />
251 243
     <editor active="true" />
252 244
     <layout>
253
-      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.14378029" />
245
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.14378029" />
254 246
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
255 247
       <window_info id="Image Layers" order="2" />
256 248
       <window_info id="Designer" order="3" />
@@ -268,7 +260,7 @@
268 260
       <window_info anchor="bottom" id="Terminal" order="8" />
269 261
       <window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
270 262
       <window_info anchor="bottom" id="Version Control" order="10" />
271
-      <window_info anchor="bottom" id="Database Console" order="11" visible="true" weight="0.554295" />
263
+      <window_info active="true" anchor="bottom" id="Database Console" order="11" visible="true" weight="0.554295" />
272 264
       <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
273 265
       <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
274 266
       <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@@ -348,6 +340,20 @@
348 340
         </state>
349 341
       </provider>
350 342
     </entry>
343
+    <entry file="file://$PROJECT_DIR$/Part 2: Simple Selects &amp; Counts">
344
+      <provider selected="true" editor-type-id="text-editor">
345
+        <state relative-caret-position="255">
346
+          <caret line="17" column="30" lean-forward="true" selection-start-line="17" selection-start-column="30" selection-end-line="17" selection-end-column="30" />
347
+        </state>
348
+      </provider>
349
+    </entry>
350
+    <entry file="file://$PROJECT_DIR$/Part 3: Joins &amp; Groups.sql">
351
+      <provider selected="true" editor-type-id="text-editor">
352
+        <state relative-caret-position="136">
353
+          <caret line="54" column="32" lean-forward="true" selection-start-line="54" selection-start-column="32" selection-end-line="54" selection-end-column="32" />
354
+        </state>
355
+      </provider>
356
+    </entry>
351 357
     <entry file="das://94ae8ad0-e995-46af-8cec-36a75eeb1c90/schema/pokemon/table/pokemon_trainer">
352 358
       <provider selected="true" editor-type-id="com.intellij.database.editor.DatabaseTableFileEditorProvider">
353 359
         <state>
@@ -357,22 +363,15 @@
357 363
     </entry>
358 364
     <entry file="file://$APPLICATION_CONFIG_DIR$/consoles/db/94ae8ad0-e995-46af-8cec-36a75eeb1c90/console.sql">
359 365
       <provider selected="true" editor-type-id="text-editor">
360
-        <state relative-caret-position="15">
361
-          <caret line="1" selection-start-line="1" selection-end-line="8" selection-end-column="23" />
362
-        </state>
363
-      </provider>
364
-    </entry>
365
-    <entry file="file://$PROJECT_DIR$/Part 3: Joins &amp; Groups.sql">
366
-      <provider selected="true" editor-type-id="text-editor">
367
-        <state relative-caret-position="540">
368
-          <caret line="36" lean-forward="true" selection-start-line="36" selection-end-line="36" />
366
+        <state>
367
+          <caret selection-end-line="14" selection-end-column="54" />
369 368
         </state>
370 369
       </provider>
371 370
     </entry>
372
-    <entry file="file://$PROJECT_DIR$/Part 2: Simple Selects &amp; Counts">
371
+    <entry file="file://$PROJECT_DIR$/Part 4: Final Report.sql">
373 372
       <provider selected="true" editor-type-id="text-editor">
374
-        <state relative-caret-position="106">
375
-          <caret line="17" column="30" lean-forward="true" selection-start-line="17" selection-start-column="30" selection-end-line="17" selection-end-column="30" />
373
+        <state relative-caret-position="75">
374
+          <caret line="14" column="54" selection-start-line="14" selection-start-column="54" selection-end-line="14" selection-end-column="54" />
376 375
         </state>
377 376
       </provider>
378 377
     </entry>

+ 16
- 0
Part 3: Joins & Groups.sql ファイルの表示

@@ -36,4 +36,20 @@ ON p.primary_type = t.id
36 36
 GROUP BY t.name;
37 37
 
38 38
 #How many pokemon at level 100 does each trainer with at least one level 100 pokemon have?
39
+SELECT t.trainername as "Trainer", pt.pokelevel
40
+FROM pokemon.trainers t
41
+JOIN pokemon.pokemon_trainer pt
42
+ON pt.trainerID = t.trainerID
43
+WHERE pt.pokelevel = 100
44
+GROUP BY t.trainername;
39 45
 
46
+#How many pokemon only belong to one trainer and no other?
47
+SELECT p.name as "Pokemon",
48
+       COUNT(t.trainername) as "Trainers"
49
+FROM pokemon.pokemons p
50
+    JOIN pokemon.pokemon_trainer pt
51
+    ON pt.pokemon_id = p.id
52
+JOIN pokemon.trainers t
53
+ON pt.trainerID = t.trainerID
54
+GROUP BY p.name
55
+HAVING COUNT(t.trainername) = 1;

+ 19
- 0
Part 4: Final Report.sql ファイルの表示

@@ -0,0 +1,19 @@
1
+SELECT p.name as "Pokemon",
2
+       tr.trainername as "Trainer",
3
+       pt.pokelevel as "Level",
4
+       ty.name as "Primary Type",
5
+       ty2.name as "Secondary Type"
6
+FROM pokemon.trainers tr
7
+JOIN pokemon.pokemon_trainer pt
8
+  ON pt.trainerID = tr.trainerID
9
+JOIN pokemon.pokemons p
10
+  ON p.id = pt.pokemon_id
11
+JOIN pokemon.types ty
12
+  ON p.primary_type = ty.id
13
+JOIN pokemon.types ty2
14
+  ON p.secondary_type = ty2.id
15
+ORDER BY pt.pokelevel DESC, pt.hp DESC, pt.maxhp DESC;
16
+
17
+
18
+#I ordered them by pokelevel, with the highest pokelevel being ranked highest and then down.
19
+If there is a tie in pokelevel, they are sorted by hp, then by maxhp.