0
我有一個遞歸查詢,它提供了上週(week_no,week_start和week_end)上星期放置的訂單數量。我想爲月份分析創建一個類似的分類。將遞歸查詢從上週的週轉換爲上月的月
WITH recursive weeks (week_start, week_end, time_end, weekno) AS (
VALUES ('2015-12-27'::date, '2016-01-02'::date, '2016-04-02'::date, 1)
UNION ALL
SELECT (week_end + interval '1 day')::date,
(CASE
WHEN (week_end + interval '7 days')::date > time_end THEN time_end
ELSE (week_end + interval '7 days')::date
END)::date,
time_end,
weekno+1
FROM weeks
WHERE time_end > week_end)
任何幫助將不勝感激。