Sql 第二个查询只是一个带条件的普通连接。

Sql 第二个查询只是一个带条件的普通连接。,sql,sql-server,tsql,sql-server-2012,exists,Sql,Sql Server,Tsql,Sql Server 2012,Exists,除了 select c.custid, c.companyname from Customers c join Orders o on o.custid=c.custid where orderdate>='20070101' and orderdate<'20080101' except select c.custid, c.companyname from [TSQL2012].Sales.Customers c join [TSQL2012].Sales.Orders o on

除了

select c.custid, c.companyname
from Customers c
join
Orders o
on o.custid=c.custid
where orderdate>='20070101' and orderdate<'20080101'
except
select c.custid, c.companyname
from [TSQL2012].Sales.Customers c
join
[TSQL2012].Sales.Orders o
on o.custid=c.custid
where orderdate>='20080101' and orderdate<'20090101'
选择c.custid,c.companyname
来自客户c
参加
命令
在o.custid=c.custid上

如果orderdate>='20070101'和orderdate='20080101'以及orderdate,除了

select c.custid, c.companyname
from Customers c
join
Orders o
on o.custid=c.custid
where orderdate>='20070101' and orderdate<'20080101'
except
select c.custid, c.companyname
from [TSQL2012].Sales.Customers c
join
[TSQL2012].Sales.Orders o
on o.custid=c.custid
where orderdate>='20080101' and orderdate<'20090101'
选择c.custid,c.companyname
来自客户c
参加
命令
在o.custid=c.custid上

如果orderdate>='20070101'和orderdate='20080101'以及orderdate,您能给我们提供两个表中的一些示例数据以供使用吗?code2中的子查询将有效地查询2007年的所有客户。请记住,条件是按行计算的:如果第一个条件(
=2017
)成立,则第二个条件(
2018
)根据定义成立。当您说
年(orderdate)='2007'
时,除非引入
条件,否则它不能是任何其他条件(条件是按行计算的)。具体值不能同时为2007和其他值。能否请您提供两个表中的一些示例数据以供使用?code2中的子查询将有效地查询2007年的所有客户。请记住,条件是按行计算的:如果第一个条件(
=2017
)成立,则第二个条件(
2018
)根据定义成立。当您说
年(orderdate)='2007'
时,除非引入
条件,否则它不能是任何其他条件(条件是按行计算的)。特定值不能同时为2007和其他值。良好的性能提示。这就是所谓的。良好的性能提示。这就是所谓的。
SELECT custid
FROM orders o
WHERE YEAR(orderdate) = 2007 AND YEAR(orderdate) <> 2008 AND o.custid = 1
select c.custid, c.companyname
from Customers c
join
Orders o
on o.custid=c.custid
where orderdate>='20070101' and orderdate<'20080101'
except
select c.custid, c.companyname
from [TSQL2012].Sales.Customers c
join
[TSQL2012].Sales.Orders o
on o.custid=c.custid
where orderdate>='20080101' and orderdate<'20090101'