-
Notifications
You must be signed in to change notification settings - Fork 0
/
elpi_indicator_view.sql
228 lines (224 loc) · 9.46 KB
/
elpi_indicator_view.sql
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
CREATE OR REPLACE VIEW state_dashboard_ca.elpi_historical AS
WITH cte_elpi_nonstate_sy22 AS (
SELECT cds,
rtype,
schoolname,
districtname,
countyname,
charter_flag,
coe_flag,
dass_flag,
currdenom,
currnumer,
currprogressed,
TRY_TO_NUMBER(pctcurrprogressed,10,1) AS pctcurrprogressed,
currmaintainpl4,
TRY_TO_NUMBER(pctcurrmaintainpl4,10,1) AS pctcurrmaintainpl4,
currmaintainoth,
TRY_TO_NUMBER(pctcurrmaintainoth,10,1) AS pctcurrmaintainoth,
currdeclined,
TRY_TO_NUMBER(currstatus,10,1) AS currstatus,
statuslevel,
flag95pct,
reportingyear
FROM state_dashboard_ca.elpidownload2022
WHERE rtype = 'S'
)
, cte_elpi_state_sy22 AS (
SELECT cds,
rtype,
schoolname,
districtname,
countyname,
charter_flag,
coe_flag,
dass_flag,
currdenom,
currnumer,
currprogressed,
TRY_TO_NUMBER(pctcurrprogressed,10,1) AS pctcurrprogressed,
currmaintainpl4,
TRY_TO_NUMBER(pctcurrmaintainpl4,10,1) AS pctcurrmaintainpl4,
currmaintainoth,
TRY_TO_NUMBER(pctcurrmaintainoth,10,1) AS pctcurrmaintainoth,
currdeclined,
TRY_TO_NUMBER(currstatus,10,1) AS currstatus,
statuslevel,
flag95pct,
reportingyear
FROM state_dashboard_ca.elpidownload2022
WHERE rtype = 'X'
)
, cte_elpi_authorizer_sy22 AS (
SELECT cds,
rtype,
schoolname,
districtname,
countyname,
charter_flag,
coe_flag,
dass_flag,
currdenom,
currnumer,
currprogressed,
TRY_TO_NUMBER(pctcurrprogressed,10,1) AS pctcurrprogressed,
currmaintainpl4,
TRY_TO_NUMBER(pctcurrmaintainpl4,10,1) AS pctcurrmaintainpl4,
currmaintainoth,
TRY_TO_NUMBER(pctcurrmaintainoth,10,1) AS pctcurrmaintainoth,
currdeclined,
TRY_TO_NUMBER(currstatus,10,1) AS currstatus,
statuslevel,
flag95pct,
reportingyear
FROM state_dashboard_ca.elpidownload2022
WHERE rtype = 'D'
)
, cte_elpi_compare_sy22 AS (
SELECT cte_elpi_nonstate_sy22.*
, cte_elpi_state_sy22.currstatus AS currstatus_state
, cte_elpi_state_sy22.statuslevel AS statuslevel_state
, cte_elpi_state_sy22.pctcurrprogressed AS pctcurrprogressed_state
, cte_elpi_state_sy22.pctcurrmaintainpl4 AS pctcurrmaintainpl4_state
, cte_elpi_state_sy22.pctcurrmaintainoth AS pctcurrmaintainoth_state
, cte_elpi_nonstate_sy22.pctcurrprogressed - cte_elpi_state_sy22.pctcurrprogressed AS pctcurrprogressed_comparison_state
, cte_elpi_nonstate_sy22.pctcurrmaintainpl4 - cte_elpi_state_sy22.pctcurrmaintainpl4 AS pctcurrmaintainpl4_comparison_state
, cte_elpi_nonstate_sy22.pctcurrmaintainoth - cte_elpi_state_sy22.pctcurrmaintainoth AS pctcurrmaintainoth_comparison_state
, cte_elpi_nonstate_sy22.currstatus - cte_elpi_state_sy22.currstatus AS currstatus_comparison_state
, cte_elpi_nonstate_sy22.statuslevel - cte_elpi_state_sy22.statuslevel AS statuslevel_comparison_state
, cte_elpi_authorizer_sy22.currstatus AS currstatus_authorizer
, cte_elpi_authorizer_sy22.statuslevel AS statuslevel_authorizer
, cte_elpi_authorizer_sy22.pctcurrprogressed AS pctcurrprogressed_authorizer
, cte_elpi_authorizer_sy22.pctcurrmaintainpl4 AS pctcurrmaintainpl4_authorizer
, cte_elpi_authorizer_sy22.pctcurrmaintainoth AS pctcurrmaintainoth_authorizer
, cte_elpi_nonstate_sy22.pctcurrprogressed - cte_elpi_authorizer_sy22.pctcurrprogressed AS pctcurrprogressed_comparison_authorizer
, cte_elpi_nonstate_sy22.pctcurrmaintainpl4 - cte_elpi_authorizer_sy22.pctcurrmaintainpl4 AS pctcurrmaintainpl4_comparison_authorizer
, cte_elpi_nonstate_sy22.pctcurrmaintainoth - cte_elpi_authorizer_sy22.pctcurrmaintainoth AS pctcurrmaintainoth_comparison_authorizer
, cte_elpi_nonstate_sy22.currstatus - cte_elpi_authorizer_sy22.currstatus AS currstatus_comparison_authorizer
, cte_elpi_nonstate_sy22.statuslevel - cte_elpi_authorizer_sy22.statuslevel AS statuslevel_comparison_authorizer
FROM cte_elpi_nonstate_sy22
LEFT JOIN cte_elpi_state_sy22
LEFT JOIN cte_elpi_authorizer_sy22
ON cte_elpi_nonstate_sy22.districtname = cte_elpi_authorizer_sy22.districtname
)
, cte_elpi_nonstate_sy19 AS (
SELECT cds,
rtype,
schoolname,
districtname,
countyname,
charter_flag,
coe_flag,
dass_flag,
currdenom,
currnumer,
currprogressed,
ROUND((currprogressed / currdenom)*100,1) AS pctcurrprogressed,
currmaintainpl4,
ROUND((currmaintainpl4 / currdenom)*100,1) AS pctcurrmaintainpl4,
currmaintainoth,
ROUND((currmaintainoth / currdenom)*100,1) AS pctcurrmaintainoth,
currdeclined,
currstatus,
statuslevel,
flag95pct,
reportingyear
FROM state_dashboard_ca.elpidownload2019
WHERE rtype = 'S'
)
, cte_elpi_state_sy19 AS (
SELECT cds,
rtype,
schoolname,
districtname,
countyname,
charter_flag,
coe_flag,
dass_flag,
currdenom,
currnumer,
currprogressed,
ROUND((currprogressed / currdenom)*100,1) AS pctcurrprogressed,
currmaintainpl4,
ROUND((currmaintainpl4 / currdenom)*100,1) AS pctcurrmaintainpl4,
currmaintainoth,
ROUND((currmaintainoth / currdenom)*100,1) AS pctcurrmaintainoth,
currdeclined,
currstatus,
statuslevel,
flag95pct,
reportingyear
FROM state_dashboard_ca.elpidownload2019
WHERE rtype = 'X'
)
, cte_elpi_authorizer_sy19 AS (
SELECT cds,
rtype,
schoolname,
districtname,
countyname,
charter_flag,
coe_flag,
dass_flag,
currdenom,
currnumer,
currprogressed,
ROUND((currprogressed / currdenom)*100,1) AS pctcurrprogressed,
currmaintainpl4,
ROUND((currmaintainpl4 / currdenom)*100,1) AS pctcurrmaintainpl4,
currmaintainoth,
ROUND((currmaintainoth / currdenom)*100,1) AS pctcurrmaintainoth,
currdeclined,
currstatus,
statuslevel,
flag95pct,
reportingyear
FROM state_dashboard_ca.elpidownload2019
WHERE rtype = 'D'
)
, cte_elpi_compare_sy19 AS (
SELECT cte_elpi_nonstate_sy19.*
, cte_elpi_state_sy19.currstatus AS currstatus_state
, cte_elpi_state_sy19.statuslevel AS statuslevel_state
, cte_elpi_state_sy19.pctcurrprogressed AS pctcurrprogressed_state
, cte_elpi_state_sy19.pctcurrmaintainpl4 AS pctcurrmaintainpl4_state
, cte_elpi_state_sy19.pctcurrmaintainoth AS pctcurrmaintainoth_state
, cte_elpi_nonstate_sy19.pctcurrprogressed - cte_elpi_state_sy19.pctcurrprogressed AS pctcurrprogressed_comparison_state
, cte_elpi_nonstate_sy19.pctcurrmaintainpl4 - cte_elpi_state_sy19.pctcurrmaintainpl4 AS pctcurrmaintainpl4_comparison_state
, cte_elpi_nonstate_sy19.pctcurrmaintainoth - cte_elpi_state_sy19.pctcurrmaintainoth AS pctcurrmaintainoth_comparison_state
, cte_elpi_nonstate_sy19.currstatus - cte_elpi_state_sy19.currstatus AS currstatus_comparison_state
, cte_elpi_nonstate_sy19.statuslevel - cte_elpi_state_sy19.statuslevel AS statuslevel_comparison_state
, cte_elpi_authorizer_sy19.currstatus AS currstatus_authorizer
, cte_elpi_authorizer_sy19.statuslevel AS statuslevel_authorizer
, cte_elpi_authorizer_sy19.pctcurrprogressed AS pctcurrprogressed_authorizer
, cte_elpi_authorizer_sy19.pctcurrmaintainpl4 AS pctcurrmaintainpl4_authorizer
, cte_elpi_authorizer_sy19.pctcurrmaintainoth AS pctcurrmaintainoth_authorizer
, cte_elpi_nonstate_sy19.pctcurrprogressed - cte_elpi_authorizer_sy19.pctcurrprogressed AS pctcurrprogressed_comparison_authorizer
, cte_elpi_nonstate_sy19.pctcurrmaintainpl4 - cte_elpi_authorizer_sy19.pctcurrmaintainpl4 AS pctcurrmaintainpl4_comparison_authorizer
, cte_elpi_nonstate_sy19.pctcurrmaintainoth - cte_elpi_authorizer_sy19.pctcurrmaintainoth AS pctcurrmaintainoth_comparison_authorizer
, cte_elpi_nonstate_sy19.currstatus - cte_elpi_authorizer_sy19.currstatus AS currstatus_comparison_authorizer
, cte_elpi_nonstate_sy19.statuslevel - cte_elpi_authorizer_sy19.statuslevel AS statuslevel_comparison_authorizer
FROM cte_elpi_nonstate_sy19
LEFT JOIN cte_elpi_state_sy19
LEFT JOIN cte_elpi_authorizer_sy19
ON cte_elpi_nonstate_sy19.districtname = cte_elpi_authorizer_sy19.districtname
)
SELECT *
, CASE WHEN schoolname LIKE '%Tahoma%' THEN 'Tahoma'
WHEN schoolname LIKE '%Everest%' THEN 'Everest'
WHEN schoolname LIKE '%Prep%' THEN 'Prep'
WHEN schoolname LIKE '%Shasta%' THEN 'Shasta'
WHEN schoolname LIKE '%K2%' THEN 'K2'
WHEN schoolname LIKE '%Tam%' THEN 'Tam'
ELSE NULL END AS reported_site_short_name
FROM cte_elpi_compare_sy22
UNION ALL
SELECT *
, CASE WHEN schoolname LIKE '%Tahoma%' THEN 'Tahoma'
WHEN schoolname LIKE '%Everest%' THEN 'Everest'
WHEN schoolname LIKE '%Prep%' THEN 'Prep'
WHEN schoolname LIKE '%Shasta%' THEN 'Shasta'
WHEN schoolname LIKE '%K2%' THEN 'K2'
WHEN schoolname LIKE '%Tam%' THEN 'Tam'
ELSE NULL END AS reported_site_short_name
FROM cte_elpi_compare_sy19