-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_transactions.txt
201 lines (180 loc) Β· 20 KB
/
sample_transactions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
--CS340 Databases
--Spring 2022
--Final Project - SQL Schema Part 4/5: Simple Transactions and Interesting Queries
--Seth Weiss, Orion Junkins
--weissse@oregonstate.edu
--junkinso@oregonstate.edu
Part 4: Sample Data Basic Queries
sqlite> SELECT * FROM Agency LIMIT 5;
βββββββββββββ¬ββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β agency_id β agency_name β website_url β
βββββββββββββΌββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ€
β 0 β Central Oregon Avalanche Center β https://www.coavalanche.org/ β
β 1 β Utah Avalanche Center β https://utahavalanchecenter.org/ β
β 2 β Sierra Avalanche Center β https://www.sierraavalanchecenter.org/ β
β 3 β Wallowa Avalanche Center β https://wallowaavalanchecenter.org/ β
β 4 β Sawtooth Avalanche Center β https://www.sawtoothavalanche.com/ β
βββββββββββββ΄ββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββ
sqlite> SELECT * FROM Forecaster LIMIT 5;
βββββββββββββ¬ββββββββββ¬βββββββββββ¬ββββββββββββ
β frcstr_id β fname β lname β agency_id β
βββββββββββββΌββββββββββΌβββββββββββΌββββββββββββ€
β 0 β Joe β Smith β 0 β
β 1 β Jane β Jones β 6 β
β 2 β John β Lee β 1 β
β 3 β Jessica β Thompson β 2 β
β 4 β Jimmy β Thompson β 2 β
βββββββββββββ΄ββββββββββ΄βββββββββββ΄ββββββββββββ
sqlite> SELECT * FROM Forecast LIMIT 5;
βββββββ¬βββββββββββββ¬ββββββββββββββββββββββββ¬βββββββββββββββββββββ¬ββββββββββββββββββββββββ¬ββββββββββββ¬ββββββββββββββββββββββββ
β fid β issue_date β danger_below_treeline β danger_at_treeline β danger_above_treeline β issued_by β corresponds_to β
βββββββΌβββββββββββββΌββββββββββββββββββββββββΌβββββββββββββββββββββΌββββββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββ€
β 0 β 12-2-21 β 0 β 1 β 1 β 0 β Central Cascades β
β 1 β 12-26-21 β 1 β 1 β 1 β 1 β Southern Mountains β
β 2 β 1/1/2022 β 2 β 2 β 3 β 2 β Uintas β
β 3 β 1/1/2022 β 2 β 2 β 2 β 3 β Central Sierra Nevada β
β 4 β 1/1/2022 β 1 β 2 β 3 β 4 β Central Sierra Nevada β
βββββββ΄βββββββββββββ΄ββββββββββββββββββββββββ΄βββββββββββββββββββββ΄ββββββββββββββββββββββββ΄ββββββββββββ΄ββββββββββββββββββββββββ
sqlite> SELECT * FROM Problem LIMIT 5;
βββββββ¬ββββββ¬βββββββββββββββ¬βββββββ¬βββββββββββββ
β pid β fid β problem_type β size β likelihood β
βββββββΌββββββΌβββββββββββββββΌβββββββΌβββββββββββββ€
β 0 β 0 β Loose Dry β 1 β 1 β
β 1 β 0 β Wind Slab β 2 β 1 β
β 2 β 1 β Storm Slab β 3 β 4 β
β 3 β 1 β Wind Slab β 3 β 4 β
β 4 β 2 β Wind Slab β 3 β 4 β
βββββββ΄ββββββ΄βββββββββββββββ΄βββββββ΄βββββββββββββ
sqlite> SELECT * FROM Elevation LIMIT 5;
βββββββ¬ββββββββββββ
β pid β elevation β
βββββββΌββββββββββββ€
β 0 β 1 β
β 1 β 1 β
β 2 β 2 β
β 3 β 3 β
β 4 β 2 β
βββββββ΄ββββββββββββ
sqlite> SELECT * FROM Aspect LIMIT 5;
βββββββ¬βββββββββ
β pid β aspect β
βββββββΌβββββββββ€
β 0 β N β
β 1 β NE β
β 2 β E β
β 3 β SE β
β 4 β S β
βββββββ΄βββββββββ
sqlite> SELECT * FROM Observation LIMIT 5;
ββββββββββββββββββ¬βββββββββββββββββββ¬ββββββββββββ¬βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ¬ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β observation_id β observation_date β avalanche β observation_location β zone_name β observer_id β obs_description β
ββββββββββββββββββΌβββββββββββββββββββΌββββββββββββΌβββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββΌββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 0 β 12-2-21 β 0 β Tam McArthur Rim β Central Cascades β 0 β Dug a hand pit, good bonding. β
β 1 β 12-15-21 β 1 β Mineral Fork β Uintas β 1 β Saw remenants of slide. No cracking or wumphing. β
β 2 β 12-26-21 β 1 β Elephant's Hump β Central Sierra Nevada β 2 β Huge slide off the hump, most likely human triggered. β
β 3 β 1-2-22 β 0 β Jackson Peak β Northern Wallowas β 3 β Great snow, no cracks or wumphing, pit revealed potential persistent weak layer. β
β 4 β 1-14-22 β 1 β Avalanche Peak β Sawtooth and Western Smoky Mtns β 4 β Observered an avalanche on Avalanceh Peak! β
ββββββββββββββββββ΄βββββββββββββββββββ΄ββββββββββββ΄βββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββ΄ββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
sqlite> SELECT * FROM Observer LIMIT 5;
βββββββββββββββ¬ββββββββββ¬βββββββββββ¬ββββββββββββββββ
β observer_id β fname β lname β observer_type β
βββββββββββββββΌββββββββββΌβββββββββββΌββββββββββββββββ€
β 0 β Joe β Smith β Forecaster β
β 1 β Jane β Jones β Forecaster β
β 2 β John β Lee β Forecaster β
β 3 β Jessica β Thompson β Forecaster β
β 4 β Jimmy β Thompson β Forecaster β
βββββββββββββββ΄ββββββββββ΄βββββββββββ΄ββββββββββββββββ
sqlite> SELECT * FROM Zone LIMIT 5;
βββββββββββββββββββββββββββββββββββ¬ββββββββββββ
β zone_name β agency_id β
βββββββββββββββββββββββββββββββββββΌββββββββββββ€
β Central Cascades β 0 β
β Uintas β 1 β
β Central Sierra Nevada β 2 β
β Northern Wallowas β 3 β
β Sawtooth and Western Smoky Mtns β 4 β
βββββββββββββββββββββββββββββββββββ΄ββββββββββββ
Part 5: Interesting Queries
1) Find the most common avalanche problem in Utah.
SELECT a.agency_name, p.problem_type, COUNT(p.problem_type)
FROM Forecast as fr
INNER JOIN Problem as p
ON fr.fid = p.fid
INNER JOIN Agency as a
ON fr.issued_by = a.agency_id
WHERE issued_by=1
GROUP BY p.problem_type
ORDER BY COUNT (p.problem_type) DESC
LIMIT 1;
βββββββββββββββββββββββββ¬βββββββββββββββ¬ββββββββββββββββββββββββ
β agency_name β problem_type β COUNT(p.problem_type) β
βββββββββββββββββββββββββΌβββββββββββββββΌββββββββββββββββββββββββ€
β Utah Avalanche Center β Wind Slab β 2 β
βββββββββββββββββββββββββ΄βββββββββββββββ΄ββββββββββββββββββββββββ
2) Search forecasts from Colorado (agency id of 6) which have a problem on an eastern aspect and return an overview of each problem.
SELECT DISTINCT p.pid ,fr.issue_date, ag.agency_name, fr.corresponds_to as Zone, p.problem_type, p.size, p.likelihood, a.aspect, e.elevation
FROM Forecast as fr
JOIN Problem as p
ON fr.fid = p.fid
JOIN Aspect as a
ON p.pid = a.pid
JOIN Elevation as e
ON p.pid = e.pid
JOIN Forecaster as f
ON fr.issued_by = f.frcstr_id
JOIN Agency as ag
ON ag.agency_id = f.agency_id
WHERE a.aspect = "E" AND ag.agency_id=6
LIMIT 5;
βββββββ¬βββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββ¬βββββββββββββββββββ¬βββββββ¬βββββββββββββ¬βββββββββ¬ββββββββββββ
β pid β issue_date β agency_name β Zone β problem_type β size β likelihood β aspect β elevation β
βββββββΌβββββββββββββΌββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββΌβββββββββββββββββββΌβββββββΌβββββββββββββΌβββββββββΌββββββββββββ€
β 2 β 12-26-21 β Colorado Avalanche Information Center β Southern Mountains β Storm Slab β 3 β 4 β E β 2 β
β 15 β 1/2/2022 β Colorado Avalanche Information Center β Southern Mountains β Cornice Collapse β 2 β 3 β E β 1 β
β 21 β 1/3/2022 β Colorado Avalanche Information Center β Southern Mountains β Persistent Slab β 1 β 2 β E β 1 β
βββββββ΄βββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββ΄βββββββββββββββββββ΄βββββββ΄βββββββββββββ΄βββββββββ΄ββββββββββββ
3) Find all forecasts that involve a Wind Slab problem. Order first by zone (corresponds_to) then by issue date.
SELECT fid, issue_date, danger_below_treeline, danger_at_treeline, danger_above_treeline, issued_by as Agency, corresponds_to AS Zone, pid, problem_type, size, likelihood
FROM Forecast
NATURAL JOIN Problem
WHERE problem.problem_type = "Wind Slab"
ORDER BY corresponds_to, issue_date
LIMIT 5;
βββββββ¬βββββββββββββ¬ββββββββββββββββββββββββ¬βββββββββββββββββββββ¬ββββββββββββββββββββββββ¬βββββββββ¬ββββββββββββββββββββββββββββββββββ¬ββββββ¬βββββββββββββββ¬βββββββ¬βββββββββββββ
β fid β issue_date β danger_below_treeline β danger_at_treeline β danger_above_treeline β Agency β Zone β pid β problem_type β size β likelihood β
βββββββΌβββββββββββββΌββββββββββββββββββββββββΌβββββββββββββββββββββΌββββββββββββββββββββββββΌβββββββββΌββββββββββββββββββββββββββββββββββΌββββββΌβββββββββββββββΌβββββββΌβββββββββββββ€
β 0 β 12-2-21 β 0 β 1 β 1 β 0 β Central Cascades β 1 β Wind Slab β 2 β 1 β
β 3 β 1/1/2022 β 2 β 2 β 2 β 3 β Central Sierra Nevada β 6 β Wind Slab β 3 β 2 β
β 4 β 1/1/2022 β 1 β 2 β 3 β 4 β Central Sierra Nevada β 8 β Wind Slab β 2 β 2 β
β 10 β 1/3/2022 β 1 β 1 β 1 β 10 β Sawtooth and Western Smoky Mtns β 18 β Wind Slab β 1 β 3 β
β 8 β 1/2/2022 β 3 β 4 β 4 β 8 β Southern Mountains β 14 β Wind Slab β 2 β 4 β
βββββββ΄βββββββββββββ΄ββββββββββββββββββββββββ΄βββββββββββββββββββββ΄ββββββββββββββββββββββββ΄βββββββββ΄ββββββββββββββββββββββββββββββββββ΄ββββββ΄βββββββββββββββ΄βββββββ΄βββββββββββββ
4) Find all observation data from Oregon.
SELECT DISTINCT
o.observation_date,
z.zone_name,
o.observation_location,
CASE WHEN avalanche = 0 THEN 'No' ELSE 'Yes' END AS avalanche,
o.obs_description
FROM Observation AS o
NATURAL JOIN Zone AS z
NATURAL JOIN Agency AS a
WHERE agency_id IN (0, 3)
LIMIT 5;
ββββββββββββββββββββ¬ββββββββββββββββββββ¬βββββββββββββββββββββββ¬ββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β observation_date β zone_name β observation_location β avalanche β obs_description β
ββββββββββββββββββββΌββββββββββββββββββββΌβββββββββββββββββββββββΌββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 12-2-21 β Central Cascades β Tam McArthur Rim β No β Dug a hand pit, good bonding. β
β 1-2-22 β Northern Wallowas β Jackson Peak β No β Great snow, no cracks or wumphing, pit revealed potential persistent weak layer. β
ββββββββββββββββββββ΄ββββββββββββββββββββ΄βββββββββββββββββββββββ΄ββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
5) Find the first and last name of forecasters who have not contributed an observation.
SELECT f.fname, f.lname FROM Forecaster AS f LEFT JOIN Observer AS o ON f.fname = o.fname WHERE o.fname IS NULL;
βββββββββββββββββ¬βββββββββββββ
β fname β lname β
βββββββββββββββββΌβββββββββββββ€
β Jorge β Lopez β
β Joey JoJo Jr. β Shabadoo β
β Big β Foot β
β Healy β Fettuccine β
βββββββββββββββββ΄βββββββββββββ