0

データを null 行に転送するクエリを作成しようとしています。これは、分析関数 LAG と LEADを使用したかなり単純なクエリです。

クエリは、ウィンドウごとのパーティションがなく、security_id が 1 つしかない場合に機能します。しかし、2 番目の 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

IGNORE NULLSオンライン2を設定したので?

于 2013-01-23T15:25:46.280 に答える