MYSQL(版本5.1)中以下查询的GOT错误
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 服务器版本相对应的手册以获取正确的语法,以便在第 5 行的“select year,month,0 as fact_1,0 as fact_2,fact_3,fact_4 from table_2 ) as 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
谁能告诉我犯了什么错误?任何人都可以帮助我了解问题背后的根本原因。