我正在尝试执行以下查询并出现错误[窗口标题] SQL错误(1064):您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在第44行的''附近使用
WITH Master_CTE (`id`,`range`, `review`, `validate`)
AS (SELECT 1 as `id`,
'<1' AS `range`,
0 AS `review`,
0 AS `validate`
UNION
SELECT 2 as id,
'1-4' AS `range`,
0 AS `review`,
0 AS `validate`
UNION
SELECT 3 as `id`,
'4-8' AS `range`,
0 AS `review`,
0 AS `validate`
UNION
SELECT 4 as `id`,
'8-24' AS `range`,
0 AS `review`,
0 AS `validate`
UNION
SELECT 5 as `id`,
'>24' AS `range`,
0 AS `review`,
0 AS `validate`)
SELECT
mc.id,
IFNULL(t.time_taken, mc.range) AS `range`,
IFNULL(t.review, mc.review) AS `review`,
IFNULL(t.validate, mc.validate) AS `validate`
FROM Master_CTE mc LEFT OUTER JOIN
(SELECT m.range AS `range`,
Ifnull((SELECT Count(r.req_status) AS `reviewcount`
FROM T1 r
WHERE r.req_status = 'READY_FOR_REV'
AND r.time_taken = m.range
GROUP BY r.time_taken), 0) `review`,
Ifnull((SELECT Count(s.req_status) AS `reviewcount `
FROM T1 s
WHERE s.req_status = 'READY_FOR_VAL'
AND s.time_taken = m.range
GROUP BY s.time_taken), 0) `validate`
FROM V1 m
GROUP BY m.range) t
表名替换为T1,视图名替换为V1。
当我单独运行时,LEFT OUTER JOIN之后的子查询工作正常,但是当我将它们组合在一起时,它开始出现错误,如标题所示。
请帮助
答案 0 :(得分:0)
LEFT OUTER JOIN
缺少联接条件,即ON t.range=mc.range
之类的内容,或者您的联接条件应该在结尾处正确。