如何为缺少周末数据建模最后一个值

时间:2013-01-23 15:18:38

标签: oracle analytics data-modeling

我正在尝试创建一个将数据转发到空行的查询。这是一个使用analytic functions LAG and LEAD

的相当简单的查询

当窗口没有分区且只有一个security_id时,查询有效。但是,当我添加该分区和第二个security_id时,last_value函数失败。粗体行不会出现。

有什么想法吗?

谢谢!

enter image description here

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 

1 个答案:

答案 0 :(得分:0)

因为您在第2行设置了IGNORE NULLS