查询未在SQL Server中运行

时间:2018-06-07 04:23:57

标签: sql-server

我有这个我在SQL Server中运行的select语句。但它引发了一个错误:

select count(*) 
from
    (select zip from A
     minus
     select zip from B)

错误:

  

选择

附近的语法不正确

这是什么问题?我也试过别名子查询但发生了同样的错误。

1 个答案:

答案 0 :(得分:1)

SQL Server中没有任何名为minus的内容,您需要使用except

注意,SQL Server中的except等同于Oracle的minus

以下查询将有效。

select count(*) ct
from
    (
     select zip from A
     except
     select zip from B
   )t

您的代码的另一个问题是您需要为正在创建的内部表提供别名。