我有一个窗口函数,它使用 rank() 操作将最近的 DHCP 日志事件与 IP 地址相匹配,从而将 IP 与主机名相关联。问题是查询不能很好地扩展到大型数据集,因此我想尝试根据 group by 重写它,但我没有成功。
create table large_table as
select column1, column2, column3, column4, column5, column6
from
(
select
a.column1, a.column2, a.start_time,
rank() OVER(
PARTITION BY a.column2, a.column1 order by a.start_time DESC
) as rank,
last_value( a.column3) OVER (
PARTITION BY a.column2, a.column1 order by a.start_time ASC
RANGE BETWEEN unbounded preceding and unbounded following
) as column3,
a.column4, a.column5, a.column6
from
(table2 s
INNER JOIN table3 t
ON s.column2=t.column2 and s.event_time > t.start_time
) a
) b
where rank =1;
问题1:我们如何使用group by而不是窗口函数来重写上面的查询?