表_A ------------------ 援助 ------------------ 1 表_B ------------------ B_id | 援助 ------------------ 1 1 2 1 3 1 表_C ----------------------------------------- B_id | 处理日期 ----------------------------------------- 1 20130101 12:20:01 2 20130101 12:10:01 3 20130101 13:00:01
如何process_date
从基于时序窗口Table_C
的参考中检索最大值。如果我想检索并在计时窗口中,那么它应该返回 id 作为 1 和 process_date 作为Table_A.A_id
Table_C
Table_C.b_id
max(process_date)
20130101 12:09:00
12:21:00
12:20:01
下面的查询是我正在使用:
select b_id,
process_date
from (select c1.b_id,
c1.process_date,
row_number() over(partition by a.a_id
order by c1.process_date desc) rn
from table_a a
inner join
table_b b
on a.a_id = b.a_id
inner join
table_c c1
on b.b_id = c1.b_id
)
where rn = 1;