You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aws/redshift/tables/regional_partner_stats_csf.sql
+9-46Lines changed: 9 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -17,42 +17,6 @@ drop table if exists analysis_pii.regional_partner_stats_csf;
17
17
createtableanalysis_pii.regional_partner_stats_csf AS
18
18
19
19
with
20
-
csf_teachers_trained_temp as
21
-
(
22
-
select distinct
23
-
user_id, -- multiple entries per person (if they attended multiple workshops)
24
-
u.studio_person_id,
25
-
'CS Fundamentals'::varcharas course,
26
-
school_year as school_year,
27
-
regional_partner as regional_partner,
28
-
regional_partner_id as regional_partner_id,
29
-
trained_at as trained_at, -- this is the 'min' date from the teachers trained at table (the first time they were trained)
30
-
workshop_date as workshop_date -- this is the date of the workshop (and the source of multiple entries per person)
31
-
from
32
-
(
33
-
SELECT
34
-
ctt.user_id,
35
-
ctt.trained_at,
36
-
pds.startas workshop_date,
37
-
regional_partner_id::int,
38
-
rp.name::varcharas regional_partner
39
-
FROM
40
-
analysis.csf_teachers_trained ctt
41
-
LEFT JOINdashboard_production_pii.pd_enrollments pde
42
-
ONpde.user_id=ctt.user_id
43
-
LEFT JOINdashboard_production_pii.pd_attendances pda
44
-
ONpda.pd_enrollment_id=pde.id
45
-
LEFT JOINdashboard_production_pii.pd_workshops pdw
46
-
ONpdw.id=pde.pd_workshop_id
47
-
AND course ='CS Fundamentals'
48
-
LEFT JOINdashboard_production_pii.pd_sessions pds
49
-
ONpds.pd_workshop_id=pdw.id
50
-
LEFT JOINdashboard_production_pii.regional_partners rp
51
-
ONpdw.regional_partner_id=rp.id
52
-
) csf_train
53
-
JOINanalysis.training_school_years sy oncsf_train.trained_at between sy.started_atandsy.ended_at
54
-
JOINdashboard_production.users u onu.id=csf_train.user_id
55
-
),
56
20
completed as
57
21
(
58
22
select
@@ -93,12 +57,12 @@ pd_facilitators as
93
57
)
94
58
SELECT distinct
95
59
d.user_id,
96
-
d.studio_person_id,
60
+
u.studio_person_id,
97
61
FIRST_VALUE(pde.first_name) OVER (PARTITION BY d.user_idORDER BY (CASE WHEN pde.first_name IS NULL THEN 1 ELSE 2 END), pde.pd_workshop_idDESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) as first_name,
98
62
FIRST_VALUE(pde.last_name) OVER (PARTITION BY d.user_idORDER BY (CASE WHEN pde.last_name IS NULL THEN 1 ELSE 2 END), pde.pd_workshop_idDESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) as last_name,
99
63
FIRST_VALUE(pde.email) OVER (PARTITION BY d.user_idORDER BY (CASE WHEN pde.email IS NULL THEN 1 ELSE 2 END), pde.pd_workshop_idDESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) as email,
100
-
d.course,
101
-
d.school_yearas school_year_trained,
64
+
'CS Fundamentals'::varcharascourse,
65
+
sy.school_yearas school_year_trained,
102
66
s.school_yearas school_year_taught,
103
67
s.script_name,
104
68
CASE WHEN rp.name is null THEN 'No Partner' ELSE rp.name END as regional_partner_name,
@@ -116,7 +80,7 @@ pd_facilitators as
116
80
CASE WHEN csfa.subject is null THEN 'Intro Workshop' else csfa.subject END as subject,
117
81
CASE WHEN csfa.trained_by_regional_partner is null then 0 else csfa.trained_by_regional_partner END as trained_by_regional_partner,
118
82
d.trained_atas trained_at,
119
-
coalesce(d.workshop_date, csfa.workshop_date, d.trained_at) as workshop_date,
83
+
coalesce(csfa.workshop_date, d.trained_at) as workshop_date,
JOIN training_school_years sy ond.trained_at between sy.started_atandsy.ended_at
137
102
-- school info
138
103
LEFT JOINdashboard_production_pii.users u -- users needed to get school_info_id
139
104
ONd.user_id=u.id
@@ -145,9 +110,7 @@ pd_facilitators as
145
110
-- LEFT JOIN analysis.csf_workshop_attendance csfa -- functions mostly to get the regional partner's location info and to decide whether the person was 'trained_by_partner'
146
111
LEFT JOINanalysis.csf_workshop_attendance csfa
147
112
ONcsfa.user_id=d.user_id
148
-
ANDcsfa.course=d.course
149
-
ANDcsfa.school_year=d.school_year
150
-
-- AND trunc(csfa.workshop_date) = d.trained_at -- this must be the PROBLEM!! investigat it
113
+
ANDcsfa.school_year=sy.school_year
151
114
ANDcsfa.not_attended=0
152
115
--pii tables (regional partner names, person names, emails, locations)
153
116
LEFT JOIN pd_facilitators pwf
@@ -156,11 +119,11 @@ pd_facilitators as
156
119
ONcsfa.regional_partner_id=rp.id
157
120
LEFT JOIN pd_enrollments_with_year pde -- only join pde if they are are trained by regional partner
0 commit comments