Sfoglia il codice sorgente

Complete lab w/Code

Chaitali Patel 6 anni fa
parent
commit
d3b3f7e718
2 ha cambiato i file con 106 aggiunte e 26 eliminazioni
  1. 105
    26
      .idea/workspace.xml
  2. 1
    0
      pokemon_sql/Pokemon.sql

+ 105
- 26
.idea/workspace.xml Vedi File

@@ -2,10 +2,7 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="cce8ec95-bbb8-4033-a9b1-09f90cbf6904" name="Default Changelist" comment="">
5
-      <change afterPath="$PROJECT_DIR$/.idea/dataSources.xml" afterDir="false" />
6
-      <change afterPath="$PROJECT_DIR$/.idea/dictionaries/chaitalipatel.xml" afterDir="false" />
7
-      <change afterPath="$PROJECT_DIR$/.idea/sqldialects.xml" afterDir="false" />
8
-      <change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
5
+      <change afterPath="$PROJECT_DIR$/pokemon_sql/Pokemon.sql" afterDir="false" />
9 6
     </list>
10 7
     <ignored path="$PROJECT_DIR$/target/" />
11 8
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -83,23 +80,55 @@
83 80
       <usages-collector id="statistics.spring.boot.run.usages" />
84 81
       <usages-collector id="statistics.js.language.service.starts" />
85 82
     </session>
83
+    <session id="-1715640155">
84
+      <usages-collector id="statistics.lifecycle.project">
85
+        <counts>
86
+          <entry key="project.open.time.3" value="1" />
87
+          <entry key="project.opened" value="1" />
88
+        </counts>
89
+      </usages-collector>
90
+      <usages-collector id="statistics.file.extensions.open">
91
+        <counts>
92
+          <entry key="iml" value="1" />
93
+          <entry key="sql" value="1" />
94
+          <entry key="xml" value="2" />
95
+        </counts>
96
+      </usages-collector>
97
+      <usages-collector id="statistics.file.types.open">
98
+        <counts>
99
+          <entry key="IDEA_MODULE" value="1" />
100
+          <entry key="SQL" value="1" />
101
+          <entry key="XML" value="2" />
102
+        </counts>
103
+      </usages-collector>
104
+      <usages-collector id="statistics.file.extensions.edit">
105
+        <counts>
106
+          <entry key="sql" value="11" />
107
+        </counts>
108
+      </usages-collector>
109
+      <usages-collector id="statistics.file.types.edit">
110
+        <counts>
111
+          <entry key="SQL" value="11" />
112
+        </counts>
113
+      </usages-collector>
114
+    </session>
86 115
   </component>
87 116
   <component name="FileEditorManager">
88 117
     <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
89
-      <file pinned="false" current-in-tab="true">
118
+      <file pinned="false" current-in-tab="false">
90 119
         <entry file="file://$APPLICATION_CONFIG_DIR$/consoles/db/43f36633-d5e3-48aa-8a38-e02c40ed677d/console.sql">
91 120
           <provider selected="true" editor-type-id="text-editor">
92
-            <state relative-caret-position="240">
93
-              <caret line="16" column="10" lean-forward="true" selection-start-line="16" selection-start-column="10" selection-end-line="16" selection-end-column="10" />
121
+            <state relative-caret-position="650">
122
+              <caret line="112" lean-forward="true" selection-end-line="112" />
94 123
             </state>
95 124
           </provider>
96 125
         </entry>
97 126
       </file>
98
-      <file pinned="false" current-in-tab="false">
99
-        <entry file="das://43f36633-d5e3-48aa-8a38-e02c40ed677d/schema/pokemon/table/pokemons">
100
-          <provider selected="true" editor-type-id="com.intellij.database.editor.DatabaseTableFileEditorProvider">
101
-            <state>
102
-              <filtering enabled="true" />
127
+      <file pinned="false" current-in-tab="true">
128
+        <entry file="file://$PROJECT_DIR$/pokemon_sql/Pokemon.sql">
129
+          <provider selected="true" editor-type-id="text-editor">
130
+            <state relative-caret-position="105">
131
+              <caret line="7" column="14" selection-start-line="7" selection-start-column="14" selection-end-line="7" selection-end-column="14" />
103 132
             </state>
104 133
           </provider>
105 134
         </entry>
@@ -113,6 +142,7 @@
113 142
     <option name="CHANGED_PATHS">
114 143
       <list>
115 144
         <option value="$APPLICATION_CONFIG_DIR$/consoles/db/43f36633-d5e3-48aa-8a38-e02c40ed677d/console.sql" />
145
+        <option value="$PROJECT_DIR$/pokemon_sql/Pokemon.sql" />
116 146
       </list>
117 147
     </option>
118 148
   </component>
@@ -122,11 +152,17 @@
122 152
     <detection-done>true</detection-done>
123 153
     <sorting>DEFINITION_ORDER</sorting>
124 154
   </component>
125
-  <component name="ProjectFrameBounds">
126
-    <option name="x" value="493" />
127
-    <option name="y" value="23" />
128
-    <option name="width" value="780" />
129
-    <option name="height" value="716" />
155
+  <component name="MavenImportPreferences">
156
+    <option name="importingSettings">
157
+      <MavenImportingSettings>
158
+        <option name="importAutomatically" value="true" />
159
+      </MavenImportingSettings>
160
+    </option>
161
+  </component>
162
+  <component name="ProjectFrameBounds" fullScreen="true">
163
+    <option name="y" value="30" />
164
+    <option name="width" value="1280" />
165
+    <option name="height" value="715" />
130 166
   </component>
131 167
   <component name="ProjectInspectionProfilesVisibleTreeState">
132 168
     <entry key="Project Default">
@@ -208,7 +244,7 @@
208 244
     <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1541540318669" />
209 245
     <property name="com.intellij.ide.scratch.LRUPopupBuilder$1/SQL Dialect" value="MySQL" />
210 246
     <property name="database.console.LAST_STATE" value="true" />
211
-    <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
247
+    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
212 248
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
213 249
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
214 250
     <property name="settings.editor.selected.configurable" value="preferences.sourceCode" />
@@ -237,17 +273,17 @@
237 273
       <updated>1541538405706</updated>
238 274
       <workItem from="1541538408546" duration="2143000" />
239 275
       <workItem from="1541540647163" duration="701000" />
276
+      <workItem from="1541802549861" duration="251000" />
240 277
     </task>
241 278
     <servers />
242 279
   </component>
243 280
   <component name="TimeTrackingManager">
244
-    <option name="totallyTimeSpent" value="2844000" />
281
+    <option name="totallyTimeSpent" value="3095000" />
245 282
   </component>
246 283
   <component name="ToolWindowManager">
247
-    <frame x="593" y="23" width="680" height="716" extended-state="0" />
248
-    <editor active="true" />
284
+    <frame x="0" y="0" width="1280" height="800" extended-state="0" />
249 285
     <layout>
250
-      <window_info content_ui="combo" id="Project" order="0" weight="0.2492163" />
286
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.2358643" />
251 287
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
252 288
       <window_info id="Image Layers" order="2" />
253 289
       <window_info id="Designer" order="3" />
@@ -261,7 +297,7 @@
261 297
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
262 298
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
263 299
       <window_info anchor="bottom" id="TODO" order="6" />
264
-      <window_info active="true" anchor="bottom" id="Database Console" order="7" visible="true" weight="0.32852563" />
300
+      <window_info anchor="bottom" id="Database Console" order="7" weight="0.32739726" />
265 301
       <window_info anchor="bottom" id="Version Control" order="8" show_stripe_button="false" />
266 302
       <window_info anchor="bottom" id="Database Changes" order="9" />
267 303
       <window_info anchor="bottom" id="Terminal" order="10" />
@@ -273,9 +309,39 @@
273 309
       <window_info anchor="right" id="Capture Analysis" order="4" />
274 310
       <window_info anchor="right" id="Theme Preview" order="5" />
275 311
       <window_info anchor="right" id="Palette&#9;" order="6" />
276
-      <window_info anchor="right" id="Database" order="7" visible="true" weight="0.34012538" />
312
+      <window_info anchor="right" id="Database" order="7" weight="0.20274636" />
277 313
       <window_info anchor="right" id="Maven Projects" order="8" />
278 314
     </layout>
315
+    <layout-to-restore>
316
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.2358643" />
317
+      <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
318
+      <window_info id="Image Layers" order="2" />
319
+      <window_info id="Designer" order="3" />
320
+      <window_info id="UI Designer" order="4" />
321
+      <window_info id="Capture Tool" order="5" />
322
+      <window_info id="Favorites" order="6" side_tool="true" />
323
+      <window_info anchor="bottom" id="Message" order="0" />
324
+      <window_info anchor="bottom" id="Find" order="1" />
325
+      <window_info anchor="bottom" id="Run" order="2" weight="0.32852563" />
326
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
327
+      <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
328
+      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
329
+      <window_info anchor="bottom" id="TODO" order="6" />
330
+      <window_info active="true" anchor="bottom" id="Database Console" order="7" visible="true" weight="0.32852563" />
331
+      <window_info anchor="bottom" id="Version Control" order="8" show_stripe_button="false" />
332
+      <window_info anchor="bottom" id="Database Changes" order="9" />
333
+      <window_info anchor="bottom" id="Terminal" order="10" />
334
+      <window_info anchor="bottom" id="Event Log" order="11" side_tool="true" />
335
+      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
336
+      <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
337
+      <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
338
+      <window_info anchor="right" id="Palette" order="3" />
339
+      <window_info anchor="right" id="Capture Analysis" order="4" />
340
+      <window_info anchor="right" id="Theme Preview" order="5" />
341
+      <window_info anchor="right" id="Palette&#9;" order="6" />
342
+      <window_info anchor="right" id="Database" order="7" visible="true" weight="0.20274636" />
343
+      <window_info anchor="right" id="Maven Projects" order="8" />
344
+    </layout-to-restore>
279 345
   </component>
280 346
   <component name="TypeScriptGeneratedFilesManager">
281 347
     <option name="version" value="1" />
@@ -298,6 +364,12 @@
298 364
         </state>
299 365
       </provider>
300 366
     </entry>
367
+    <entry file="file://$PROJECT_DIR$/.idea/dataSources/43f36633-d5e3-48aa-8a38-e02c40ed677d.xml">
368
+      <provider selected="true" editor-type-id="text-editor" />
369
+    </entry>
370
+    <entry file="file://$PROJECT_DIR$/PokemonSqlLab.iml">
371
+      <provider selected="true" editor-type-id="text-editor" />
372
+    </entry>
301 373
     <entry file="das://43f36633-d5e3-48aa-8a38-e02c40ed677d/schema/pokemon/table/pokemons">
302 374
       <provider selected="true" editor-type-id="com.intellij.database.editor.DatabaseTableFileEditorProvider">
303 375
         <state>
@@ -307,8 +379,15 @@
307 379
     </entry>
308 380
     <entry file="file://$APPLICATION_CONFIG_DIR$/consoles/db/43f36633-d5e3-48aa-8a38-e02c40ed677d/console.sql">
309 381
       <provider selected="true" editor-type-id="text-editor">
310
-        <state relative-caret-position="240">
311
-          <caret line="16" column="10" lean-forward="true" selection-start-line="16" selection-start-column="10" selection-end-line="16" selection-end-column="10" />
382
+        <state relative-caret-position="650">
383
+          <caret line="112" lean-forward="true" selection-end-line="112" />
384
+        </state>
385
+      </provider>
386
+    </entry>
387
+    <entry file="file://$PROJECT_DIR$/pokemon_sql/Pokemon.sql">
388
+      <provider selected="true" editor-type-id="text-editor">
389
+        <state relative-caret-position="105">
390
+          <caret line="7" column="14" selection-start-line="7" selection-start-column="14" selection-end-line="7" selection-end-column="14" />
312 391
         </state>
313 392
       </provider>
314 393
     </entry>

+ 1
- 0
pokemon_sql/Pokemon.sql Vedi File

@@ -0,0 +1 @@
1
+/*Part 1*/
/*What are all the types of pokemon that a pokemon can have?*/
select distinct name from pokemon.pokemons order by name;

/*What is the name of the pokemon with id 45?*/
select * from pokemon.pokemons where id = 45;

/*How many pokemon are there?*/
select count(ID) from pokemon.pokemons;

/*How many types are there?*/
select * from pokemon.types;

/*How many pokemon have a secondary type?*/
select count(distinct (secondary_type))
from pokemon.pokemons;


/*Part 3*/
/*What is each pokemon's primary type?*/
select t.name as name_type, pk.name as pokemon_name, pk.primary_type  from pokemon.pokemons  pk
                left join pokemon.types t
                  on pk.primary_type = t.id;

/*What is Rufflet's secondary type?*/

select t.name as name_type, pk.name as pokemon_name, pk.secondary_type
from pokemon.pokemons  pk
left join pokemon.types t
on pk.secondary_type = t.id
    where pk.name = "Rufflet";

/*What are the names of the pokemon that belong to the
trainer with trainerID 303?*/

select distinct(pok.name) as pokemon_name,
       t.trainerID as trainer_id,
       pk.trainername as trainer_name
from pokemon.trainers  pk
       left join pokemon.pokemon_trainer t
         on pk.trainerID = t.trainerID
      left join pokemon.pokemons pok
          on pok.id =t.pokemon_id
          where pk.trainerID = 303;

/*How many pokemon have a secondary type Poison*/
select count(pk.name) as num_of_pokemon,
       t.name as name_type,
       pk.secondary_type
from pokemon.pokemons  pk
       left join pokemon.types t
         on pk.secondary_type = t.id
where t.name in ("poison")
group by t.name,pk.secondary_type;


/*What are all the primary types and how many
pokemon have that type? */

select count(pk.name) as num_of_pokm_prim_typ,
       t.name as prim_name_type,
       pk.primary_type as primary_type_id
from pokemon.pokemons  pk
left join pokemon.types t
on pk.primary_type = t.id
where pk.primary_type is not null
group by t.name, pk.primary_type
order by num_of_pokm_prim_typ desc;


/*How many pokemon at level 100 does each trainer with at
least one level 100 pokemon have? (Hint: your query should
not display a trainer*/

select count(pok.name) as num_of_pokmn,
               t.pokelevel
from pokemon.pokemon_trainer t
       left join pokemon.pokemons pok
         on pok.id =t.pokemon_id
where t.pokelevel = 100
group by t.pokelevel;


/*How many pokemon only belong to one trainer
and no other?*/

select * from (
select pok.name as pokemon_name,
               count(pk.trainername) as trainer_name
from pokemon.trainers  pk
       left join pokemon.pokemon_trainer t
         on pk.trainerID = t.trainerID
       left join pokemon.pokemons pok
         on pok.id =t.pokemon_id group by pok.name) a
where a.trainer_name = 1;

# Part 4: Final Report

select pok.name as "Pokemon Name",
pk.trainername as "Trainer Name",
t.pokelevel as "Level",
ptyp.name as "Primary Type",
styp.name as "Secondary Type"
from pokemon.trainers  pk
left join pokemon.pokemon_trainer t
on pk.trainerID = t.trainerID
left join pokemon.pokemons pok
on pok.id =t.pokemon_id
left join pokemon.types ptyp
on pok.primary_type = ptyp.id
left join pokemon.types styp
 on pok.secondary_type = styp.id
order by t.pokelevel desc, pok.secondary_type desc