【发布时间】:2020-05-20 07:04:09
【问题描述】:
我想在相同 gr_number 和 course 的基础上获得基于 Updated_ts 的最后一行
我正在使用以下查询。
select t.*
from (select st.gr_number,st.course,st.is_active_flg,st.status,st.updated_ts
,sum(case when st.status = 'COMPLETED' then 1 else 0 end) over (partition by st.gr_number) as completedCourse,
sum(case when st.status <> 'COMPLETED' and st.status <> 'APPLICATION' and st.is_active_flg = 'N' then 1 else 0 end) over (partition by st.gr_number) as IncompletCourse
from admission_log st
join course cr on cr.course_id=st.course
order by st.gr_number,st.course,st.updated_ts
) t
where completedCourse > 0 and IncompletCourse > 0;
这个查询给我的结果是
从上面的结果中,我只想要基于 Updated_ts 的相同 gr_number 和课程的最后一个值
喜欢
请帮忙
【问题讨论】:
标签: sql oracle greatest-n-per-group