select *
from mytable
where as_of_date in (select max(as_of_date) from mytable where as_of_date between first_day(add_months(current_date, -1)) and last_day(add_months(current_date, -1))
或者像这样(单扫描+分析函数)
select col1 ... colN
from
(
select t.*, rank() over (partition by month (t.as_of_date) order by t.as_of_date desc) rnk
from mytable t
where --If you have partition on date, this WHERE may improve performance
t.as_of_date between first_day(add_months(current_date, -1)) and last_day(add_months(current_date, -1))
)s
where rnk=1
1条答案
按热度按时间5n0oy7gb1#
例如,如下所示(表的两次扫描:一次在子查询中查找max date,另一次在主查询中):
或者像这样(单扫描+分析函数)