第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
学习Microsoft SQL Server 2008技术内幕:T-SQL语法基础--第4章
原文:http://www.cnblogs.com/easy5weikai/p/5555644.html