Skip to content

Commit

Permalink
fix: add latest grade for fact_grade_status model
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Feb 28, 2024
1 parent 250f4af commit d058b4e
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions models/grading/fact_grade_status.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,38 @@ with
'http://adlnet.gov/expapi/verbs/passed',
'http://adlnet.gov/expapi/verbs/failed'
)
),

latest_course_grades as (
select
org,
course_key,
actor_id,
scaled_score as course_grade,
row_number() over (
partition by org, course_key, actor_id order by emission_time desc
) as rn
from {{ ref("fact_grades") }}
where grade_type = 'course'
)

select
lg.org,
lg.course_key,
lg.object_id,
lg.actor_id,
lg.latest_state as latest_grade_state
lg.org as org,
lg.course_key as course_key,
lg.object_id as object_id,
lg.actor_id as actor_id,
lg.latest_state as latest_state,
lc.course_grade as course_grade
from latest_grades lg
join
latest_grade_status lgs
on lg.org = lgs.org
and lg.course_key = lgs.course_key
and lg.object_id = lgs.object_id
and lg.actor_id = lgs.actor_id
where lg.rn = 1
left join
latest_course_grades lc
on lg.org = lc.org
and lg.course_key = lc.course_key
and lg.actor_id = lc.actor_id
where lg.rn = 1 and lc.rn = 1

0 comments on commit d058b4e

Please sign in to comment.