create table SkuXFcst as SELECT 21257 as item, 903 as loc, TO_DATE('2018-12-11')as startdate, 14400 as dur , 100 as qty from dual union all SELECT 21257, 664, TO_DATE('2018-12-10'), 14400, 100 from dual union all SELECT 11064, 101, TO_DATE('2018-11-26'), 43200, 300 from dual union all SELECT 21257, 315, TO_DATE('2018-12-01'), 14400, 100 from dual union all SELECT 21257, 314, TO_DATE('2018-12-10'), 14400, 100 from dual union all SELECT 21257, 903, TO_DATE('2018-12-10'), 14400, 1000 from dual union all SELECT 19510, 502, TO_DATE('2018-12-20'), 14400, 50 from dual union all SELECT 19510, 502, TO_DATE('2018-12-20'), 14400, 500 from dual union all SELECT 19507, 615, TO_DATE('2018-12-20'), 14400, 50 from dual union all SELECT 19507, 615, TO_DATE('2018-12-22'), 14400, 50 from dual union all SELECT 19510, 502, TO_DATE('2018-12-01'), 0 , 0 from dual ; SELECT item, loc, dur, SUM(CASE WHEN SkuXFcst.StartDate BETWEEN to_date('2018-12-02','YYYY-MM-DD') AND to_date('2018-12-02','YYYY-MM-DD')+ 6 THEN SkuXFcst.Qty ELSE 0 END) AS P1, SUM(CASE WHEN SkuXFcst.StartDate BETWEEN to_date('2018-12-02','YYYY-MM-DD') + 7 AND to_date('2018-12-02','YYYY-MM-DD') + 13 THEN SkuXFcst.Qty ELSE 0 END) P8, SUM(CASE WHEN SkuXFcst.StartDate BETWEEN to_date('2018-12-02','YYYY-MM-DD') + 14 AND to_date('2018-12-02','YYYY-MM-DD') + 20 THEN SkuXFcst.Qty ELSE 0 END) P15, SUM(CASE WHEN SkuXFcst.StartDate BETWEEN to_date('2018-12-02','YYYY-MM-DD') + 21 AND to_date('2018-12-02','YYYY-MM-DD') + 27 THEN SkuXFcst.Qty ELSE 0 END) P22 from SkuXFcst GROUP BY item, loc, dur