首页 > 数据库技术 > 详细

学习Microsoft SQL Server 2008技术内幕:T-SQL语法基础--第4章

时间:2016-06-03 12:35:37      阅读:179      评论:0      收藏:0      [点我收藏+]

第4章 子查询

4.2.1 Exist 谓语:

技术分享
use TSQLFundamentals2008
select * 
from Sales.Customers as C
where c.country=NSpain

select * 
from Sales.Customers as C
where c.country=NSpain and exists(select * from Sales.Orders as O where o.custid=C.custid)

select * 
from Sales.Customers as C
where c.country=NSpain and not exists(select * from Sales.Orders as O where o.custid=C.custid)
View Code

技术分享

 

 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
View Code

 

学习Microsoft SQL Server 2008技术内幕:T-SQL语法基础--第4章

原文:http://www.cnblogs.com/easy5weikai/p/5555644.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!