任何人都可以建议“相交”的替代方案吗? & “减”对于MYSQL?
在 MYSQL(version5.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 服务器版本 在“选择”附近使用正确的语法 年、月、0 作为 fact_1,0 作为 表_2 中的事实_2、事实_3、事实_4 )为 ct g' 位于第 5 行
,但以下查询给出了所需的结果:-
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
谁能告诉我我犯了什么错误? 任何人都可以帮助我了解问题背后的根本原因。
GOT error for the following query in MYSQL(version5.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
Error Line with code#1064:-
You have an error in your SQL syntax;
check the manual that corresponds to
your MySQL server version for the
right syntax to use near 'select
year,month,0 as fact_1,0 as
fact_2,fact_3,fact_4 from table_2 ) as
ct g' at line 5
but following query was giving desired Result:-
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
Can anybody tell what error i am committing?
can Anybody help me to understand the root cause behind the Problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
INNER
(自身)JOIN
轻松伪造INTERSECT
,这样您就只能从两个结果集中获取行:MINUS
可以用 LEFT JOIN 来伪造:you can fake
INTERSECT
quite easily using anINNER
(self)JOIN
, this way you’ll only get rows from both resultsets:MINUS
can be faked with aLEFT JOIN
:MySQL 不支持 INTERSECT 关键字。 5.1 的 SELECT 完整语法如下:
http://dev.mysql .com/doc/refman/5.1/en/select.html
MySQL doesn't support the INTERSECT keyword. Full syntax of SELECT for 5.1 is here:
http://dev.mysql.com/doc/refman/5.1/en/select.html