0

我正在尝试创建一个将数据转发到空行的查询。这是一个相当简单的查询,带有分析函数 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 
4

1 回答 1

0

Because you have set an IGNORE NULLS On line 2?

于 2013-01-23T15:25:46.280 回答