Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Code Block
languagesql
themeRDark
titleActual Production
with P as (
        select 
        DAYTIME as DAYTIME, 
        sum(NET_VOL) as AP
        from dv_strm_day_pc_alloc
        where DAYTIME between (select TRUNC (sysdate,'YEAR') from DUAL) and (select TRUNC (CURRENT_DATE) from DUAL)
        and OBJECT_CODE = 'BAL1001'
        and PROFIT_CENTRE_CODE in ('BALDER_FIELD', 'RHE_FIELD', 'RH_FIELD')
        group by DAYTIME
    ),
    Q as (
        select 
        ((select TRUNC (sysdate,'YEAR') from DUAL) %2B (LEVEL - 1)) as DAYTIME,
        (select 0 from dual) as ZERO
        from DUAL
        connect by level <=( sysdate-((select TRUNC (sysdate,'YEAR') from DUAL)))    
    )
    select 
    concat(to_char(Q.DAYTIME,'YYYY-MM-DD'),'T00:00:00') as %22x%22,
    round(coalesce(P.AP,0),0) as %22y%22
    from Q 
    left join P on Q.DAYTIME = P.DAYTIME
    order by Q.DAYTIME