我需要使用子查询加入日期列表。
SELECT *
FROM (WITH daterange(level, dt)
AS (SELECT 1,
CURRENT DATE - 7 DAYS
FROM SYSIBM.sysdummy1
UNION ALL
SELECT level + 1,
dt + 1 DAY
FROM daterange
WHERE level < 1000
AND dt < CURRENT DATE - 1 DAY)
SELECT dt
FROM daterange)a
LEFT OUTER JOIN (SELECT WT.task_type_code,
DATE(WT.created_ts) AS d,
COUNT(WT.task_id) AS COUNTER
FROM workflow_task WT,
stage_item SI
WHERE WT.task_type_code IN( 2 )
AND DATE(WT.created_ts) >= '2016-03-18'
AND DATE(WT.created_ts) <= '2016-03-26'
AND SI.task_id = WT.task_id
GROUP BY WT.task_type_code,
DATE(WT.created_ts)
ORDER BY 2)b
ON( A.dt = b.d )
WITH UR;
但是它会抛出一条错误消息
访问数据库时发生错误。非法使用关键字 如。 TOKEN INNER LEFT RULL FULL CROSS JOIN;游客 SQL_CURLH200C1不在预备状态
请帮助我并建议我如何加入!!
答案 0 :(得分:0)
使用WITH
关键字开始查询,并移除最不需要的SELECT。