第4章 子查询
4.2.1 Exist 谓语:
use TSQLFundamentals2008 select * from Sales.Customers as C where c.country=N‘Spain‘ select * from Sales.Customers as C where c.country=N‘Spain‘ and exists(select * from Sales.Orders as O where o.custid=C.custid) select * from Sales.Customers as C where c.country=N‘Spain‘ and not exists(select * from Sales.Orders as O where o.custid=C.custid)
4.3.2 连续聚和
select OBJECT_ID(‘Sales.OrderTotalsByYear‘) if OBJECT_ID(‘Sales.OrderTotalsByYear‘) is not null drop view Sales.OrderTotalsByYear go create view Sales.OrderTotalsByYear with schemabinding as select YEAR(o.orderdate) as orderyear, SUM(od.qty) as qty from Sales.Orders as o join Sales.OrderDetails as od on o.orderid=od.orderid group by YEAR(o.orderdate) go
时间: 2024-11-25 07:13:41