我正在尝试创建一个将数据转发到空行的查询。这是一个相当简单的查询,带有分析函数 LAG 和 LEAD
该查询在没有按窗口分区且只有一个 security_id 时有效。但是,当我添加该分区和第二个 security_id 时,last_value 函数失败。粗体行不会出现。
有任何想法吗?
谢谢!
select t.*
,last_value(weight_pct ignore nulls) over
(partition by security_id order by n desc) value1 from (
select
datekey,portfolio_id,security_id,weight_pct
, n
from (
select to_date(first_date, 'yyyymmdd') -
to_date(datekey, 'yyyymmdd') day
,datekey
,portfolio_id
,security_id
,weight_pct
from ((select FIRST_VALUE(datekey) OVER(ORDER BY datekey desc ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as first_date,
datekey,
portfolio_id,
security_id,
WEIGHT_PCT
from foo d
where security_id in (7,658900)
and portfolio_id = 2))) d
right outer join (select level as n
from dual
connect by level <= 95) l
on d.days = l.n) t
order by n, security_id, datekey desc