我有一個遞歸的SQL,我正在運行哪些工作,但給我以下警告。db2 supress遞歸警告
SQL0347W遞歸公用表表達式「DT_LAST_YEAR」可能包含無限循環 。 SQLSTATE = 01605
我該如何擺脫警告?
INSERT INTO REP_MAN_TRAN_COUNTS (SITEDIRECTORYID, BUSINESSDATE, TRANCOUNT)
WITH dt_this_year (level, seqdate) AS
(
SELECT 1, date(current timestamp) -7 DAYS FROM sysibm.sysdummy1
UNION ALL
SELECT level, seqdate + level days FROM dt_this_year WHERE level < 1000 AND seqdate + 1 days < date(current timestamp)
)
,dt_last_year (level, seqdate) AS
(
SELECT 1, date(current timestamp) -7 DAYS - 1 year FROM sysibm.sysdummy1
UNION ALL
SELECT level, seqdate + level days FROM dt_last_year WHERE level < 1000 AND seqdate + 1 days < date(current timestamp) -1 year
)
select 10049, date(dts.calendarday), count(*) trancount
from (
SELECT seqdate AS calendarday FROM dt_this_year
UNION
SELECT seqdate AS calendarday FROM dt_last_year
) dts LEFT JOIN ccftrxheader ccf
ON date(dts.calendarday) = date(ccf.businessdate)
WHERE ccf.sitedirectoryid=10049
GROUP BY ccf.sitedirectoryid,dts.calendarday
感謝您的幫助
哇..謝謝..那真是太棒了。我對你給我的東西做了一些輕微的修改,它的工作方式和我想要的完全一樣。對不起,你可以幫我一個忙,你在和條款裏寫了些什麼。我有麻煩了解遞歸如何工作。 – Richie
@Richie - 這樣的事情? –