这是我的sql代码。当我在mysql工作台上运行它时它运行得很好但是在union不会影响最终结果的地方周围存在语法错误。我试图添加括号来分隔联合部分,但我仍然会遇到相同的语法错误。 并不是说它在我运行时似乎工作得很好。
SELECT date, time_code, number, power
FROM power_total
WHERE number IN (
SELECT number
FROM table_1 AS b
WHERE something
AND something
AND something
AND type = 1
UNION
SELECT dem.number AS number
FROM table_1 AS b
INNER JOIN (SELECT re.point_number AS number
FROM table_2 AS re
INNER JOIN table_3 AS dc
ON something = something
WHERE type_id IN (1 , 2)
AND something IS NULL
AND date <= '2016-09-01'
) AS dem
ON dem.number = b.number
)
AND date BETWEEN '20160901' AND '20160930'
答案 0 :(得分:-1)
对欲望输出使用fallowing查询:
SELECT date, time_code, number, power FROM power_total
WHERE number IN ( SELECT number FROM table_1 AS b
WHERE something =something
AND something=something
AND something=something
AND type = 1
UNION
SELECT dem.number AS number FROM table_1 AS b
INNER JOIN (SELECT re.point_number AS number FROM table_2 AS re
INNER JOIN table_3 AS dc
ON something = something
WHERE type_id IN (1 , 2)
AND something IS NULL
AND date <= '2016-09-01'
) AS dem
ON dem.number = b.number)
AND date BETWEEN '20160901' AND '20160930'