在MySQL(版本5.1)中出现以下查询错误
SELECT year,month,sum(fact_1),sum(fact_2),sum(fact_3),sum(fact_4)
from(
select year,month,fact_1,fact_2,0 as fact_3,0 as fact_4 from table_1
intersect
select year,month,0 as fact_1,0 as fact_2,fact_3,fact_4 from table_2
) as combined_table
group by month,year
代码为1064的错误行:
您的SQL语法有错误;
检查对应的手册
您的mysql服务器版本
在“select”附近使用的正确语法
年、月,0表示事实\1,0表示
表2中的事实\2、事实\3、事实\4
第5行CT G′
但以下查询给出了所需的结果:
SELECT year,month,sum(fact_1),sum(fact_2),sum(fact_3),sum(fact_4)
from(
select year,month,fact_1 ,fact_2,0 as fact_3,0 as fact_4 from table_1
union
select year,month,0 as fact_1,0 as fact_2,fact_3,fact_4 from table_2
) as ct
group by month,year
有人能告诉我犯了什么错误吗?
有人能帮我了解问题背后的根本原因吗?