Этот запрос возвращает 26 строк, которые выглядят следующим образом.
FORT_START FORT_END JULIAN_DATE SUM(ITEMS_SOLD)
--
01-JAN-10 14-JAN-10 14 15
15-JAN-10 28-JAN-10 28 -
29-JAN-10 11-FEB-10 42 7
12-FEB-10 25-FEB-10 56 -
26-FEB-10 11-MAR-10 70 13
12-MAR-10 25-MAR-10 84 -
26-MAR-10 08-APR-10 98 6
09-APR-10 22-APR-10 112 -
...
Он создает календарь - просто таблицу дат - на 2010 год. На самом деле вы не можете получить все 26 строк, не имея 26 строк для объединения.
with calendar as (
select cal_date
from
(
select to_date('01 2010','MM YYYY')-1 + level as cal_date
from dual
where (to_date('01 2010','MM YYYY')-1+level) <= last_day(to_date('12 2010','MM YYYY'))
connect by level<=365
)
order by cal_date
)
select cal_date - 13 as fort_start, cal_date as fort_end,
to_number(to_char(cal_date, 'DDD')) as julian_date, sum(items_sold)
from calendar
left join table1 on (work_date between cal_date - 13 and cal_date)
where (cal_date between date '2010-01-01' and date '2010-12-31'
and mod(to_number(to_char(cal_date, 'DDD')), 14) = 0
)
group by cal_date - 13, cal_date, to_number(to_char(cal_date, 'DDD'))
order by cal_date;