2013-01-23 2 views
0

null 행으로 전달되는 데이터를 전달하는 쿼리를 만들려고합니다. 이것은 매우 간단한 쿼리입니다. 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 

답변

0

당신이 라인 2에 IGNORE NULLS를 설정했기 때문에?