Skip to content

Commit

Permalink
Merge pull request #23372 from code-dot-org/rp_redshift_updates
Browse files Browse the repository at this point in the history
update outreach_stats_by_year
  • Loading branch information
marybarnes37 committed Jun 27, 2018
2 parents df48bd9 + 8c92c2e commit 79b7c0f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions aws/redshift/tables/outreach_stats_by_year.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ CREATE table analysis.outreach_stats_by_year AS
SELECT 'State' region_type,
ug.state region,
ug.state state,
school_year,
-- DATE_PART(year,us.created_at::DATE) AS year,
sy1.school_year school_year,
-- old ways of getting the year:
-- coalesce(sy1.school_year, sy2.school_year) as school_year,
-- DATE_PART(year,us.created_at::DATE) AS year,
COUNT(DISTINCT u.id) teachers,
COUNT(DISTINCT f.student_user_id) students,
COUNT(DISTINCT CASE WHEN u_students.gender = 'f' THEN f.student_user_id ELSE NULL END)::FLOAT/ NULLIF(COUNT(DISTINCT CASE WHEN u_students.gender IN ('m','f') THEN f.student_user_id ELSE NULL END),0) pct_female,
Expand All @@ -28,7 +30,8 @@ CREATE table analysis.outreach_stats_by_year AS
ON u_students.id = us.user_id
LEFT JOIN dashboard_production.user_proficiencies up
ON up.user_id = u_students.id
JOIN analysis.school_years sy on us.created_at between sy.started_at and sy.ended_at
LEFT JOIN analysis.school_years sy1 on us.started_at between sy1.started_at and sy1.ended_at
--LEFT JOIN analysis.school_years sy2 on us.created_at between sy2.started_at and sy2.ended_at
WHERE country = 'United States'
AND u_students.current_sign_in_at IS NOT NULL
AND u_students.user_type = 'student'
Expand All @@ -38,8 +41,10 @@ CREATE table analysis.outreach_stats_by_year AS
SELECT 'City' region_type,
ug.city|| ', ' ||ug.state region,
ug.state state,
-- DATE_PART(year,us.created_at::DATE) AS year,
school_year,
sy1.school_year school_year,
-- old ways of getting the year:
-- coalesce(sy1.school_year, sy2.school_year) as school_year,
-- DATE_PART(year,us.created_at::DATE) AS year,
COUNT(DISTINCT u.id) teachers,
COUNT(DISTINCT f.student_user_id) students,
COUNT(DISTINCT CASE WHEN u_students.gender = 'f' THEN f.student_user_id ELSE NULL END)::FLOAT/ NULLIF(COUNT(DISTINCT CASE WHEN u_students.gender IN ('m','f') THEN f.student_user_id ELSE NULL END),0) pct_female,
Expand All @@ -63,7 +68,8 @@ CREATE table analysis.outreach_stats_by_year AS
ON u_students.id = us.user_id
LEFT JOIN dashboard_production.user_proficiencies up
ON up.user_id = u_students.id
JOIN analysis.school_years sy on us.created_at between sy.started_at and sy.ended_at
LEFT JOIN analysis.school_years sy1 on us.started_at between sy1.started_at and sy1.ended_at
--LEFT JOIN analysis.school_years sy2 on us.created_at between sy2.started_at and sy2.ended_at
WHERE country = 'United States'
AND u_students.current_sign_in_at IS NOT NULL
AND u_students.user_type = 'student'
Expand Down

0 comments on commit 79b7c0f

Please sign in to comment.