-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/TEAMSchools/teamster
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/dbt/kipptaf/models/extracts/google/sheets/rpt_gsheets__community_service_upload.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
with | ||
cs_roster as ( | ||
select | ||
co.student_number, | ||
co.academic_year, | ||
co.grade_level, | ||
co.school_abbreviation as school_name, | ||
|
||
b.behavior_date, | ||
b.behavior, | ||
b.notes, | ||
|
||
cast(left(b.behavior, length(b.behavior) - 5) as int) as cs_hours, | ||
from {{ ref("base_powerschool__student_enrollments") }} as co | ||
left join | ||
{{ ref("stg_deanslist__behavior") }} as b | ||
on ( | ||
co.student_number = b.student_school_id | ||
and b.behavior_category = 'Community Service' | ||
and (b.behavior_date between co.entrydate and co.exitdate) | ||
) | ||
where | ||
co.grade_level between 9 and 12 | ||
and co.is_enrolled_y1 | ||
and co.academic_year >= {{ var("current_academic_year") }} - 1 | ||
) | ||
|
||
select | ||
academic_year, | ||
school_name, | ||
student_number as `StudentID`, | ||
_9 as `HOURS-9TH`, | ||
_10 as `HOURS-10TH`, | ||
_11 as `HOURS-11TH`, | ||
_12 as `HOURS-12TH`, | ||
from | ||
( | ||
select | ||
hs.academic_year, | ||
hs.school_name, | ||
hs.student_number, | ||
hs.grade_level, | ||
hs.cs_hours, | ||
from cs_roster as hs | ||
) | ||
pivot (sum(cs_hours) for grade_level in (9, 10, 11, 12)) |