This question already has an answer here:
这个问题在这里已有答案:
- How do I 'subtract' sql tables? 13 answers
我如何'减去'sql表? 13个答案
I have this select statement that I am running in SQL Server. But it's throwing an error:
我有这个我在SQL Server中运行的select语句。但这是一个错误:
select count(*)
from
(select zip from A
minus
select zip from B)
Error:
Incorrect syntax near select
选择附近的语法不正确
What is the issue here? I have also tried aliasing the subquery but same error happens.
这是什么问题?我也试过别名子查询但发生同样的错误。
1 个解决方案
#1
1
There is nothing called minus
in SQL Server, you need to use except
.
在SQL Server中没有任何称为减号的东西,你需要使用除外。
Note, except
in SQL Server is equivalent to minus
of Oracle
注意,除了在SQL Server中相当于Oracle的减号
Following query will work.
以下查询将起作用。
select count(*) ct
from
(
select zip from A
except
select zip from B
)t
Another issue with your code is that you need to give a alias name to the inner table you are creating.
您的代码的另一个问题是您需要为正在创建的内部表提供别名。
#1
1
There is nothing called minus
in SQL Server, you need to use except
.
在SQL Server中没有任何称为减号的东西,你需要使用除外。
Note, except
in SQL Server is equivalent to minus
of Oracle
注意,除了在SQL Server中相当于Oracle的减号
Following query will work.
以下查询将起作用。
select count(*) ct
from
(
select zip from A
except
select zip from B
)t
Another issue with your code is that you need to give a alias name to the inner table you are creating.
您的代码的另一个问题是您需要为正在创建的内部表提供别名。