易截截图软件、单文件、免安装、纯绿色、仅160KB

sql choch02

ch02
--3-4
select * from orders
where 'México D.F.' in
(select City
from Customers
where Orders.CustomerID = Customers.CustomerID )
--3-5
select * from orders
where 'usa' =
(select Country
from Customers
where Orders.CustomerID = Customers.CustomerID )
--4-1
select * from orders
where Exists
(select *
from Customers
where Orders.CustomerID = Customers.CustomerID
and City='México D.F.')
--4-2
select Customers.companyname, Suppliers.companyname,Customers.City from customers,suppliers
where customers.city = suppliers.city
order by city asc
select CompanyName, city from Customers
where City = any
(Select City from Suppliers
where Customers.city = Suppliers.city)
order by city asc
select CompanyName, city from Customers
where exists
(Select * from Suppliers
where Customers.city = Suppliers.city)
order by city asc
--5-1
select CompanyName from Customers
where CustomerID in
(
select CustomerID from Orders
where OrderID in
(
select OrderID from [Order Details]
where quantity >all(
select quantity from Customers c,Orders O,[order details] od
where c.CustomerID = O.CustomerID and O.OrderID = od.OrderID and
CompanyName ='Around the Horn')
)
)
--5-3
select CompanyName from Customers
where CustomerID in
(
select CustomerID from Orders
where OrderID in
(
select OrderID from [order details]
where quantity >any(
select quantity from Customers c,Orders O,[order details] od
where c.CustomerID = O.CustomerID and O.OrderID = od.OrderID and
CompanyName ='Around the Horn')
)
)
--5-6
select CompanyName from Customers
where CustomerID in
(
select CustomerID from Orders
where OrderID in
(
select OrderID from [order details]
where quantity >'3'
)
)
--5-7
select ProductName,UnitPrice from Products
where Exists
(
select * from Suppliers
where city='london' and suppliers.SupplierID = Products.SupplierID )


相关文档:

SQL Server 行列转换示例

SQL Server的行列转换功能非常实用,但是由于其语法不好懂,使很多初学者都不愿意使用它。下面我就用示例的形式,逐一展现Pivot和UnPivot的魅力。如下图
 
1.从Wide Table of Months 转换到 Narrow Table的示例
select [Year],[Month],[Sales] from
(
select * from MonthsTable
)p
unpivot
(
[Sales] for ......

SQL Server 2008和微软数据平台开发

Microsoft SQL Server
2008和Microsoft数据平台为开发人员提供了一个综合的编程架构,用于创建针对移动设备、桌面电脑、Web服务器,和企业服务器的基于数据的解
决方案。这个数据编程环境将数据访问和管理集成到一个应用程序的业务逻辑中,从而提高了开发人员的生产力。它提供了一个用于对异构数据源的数据访问和管理
的 ......

关于SQL Server数据库设计的感悟

转载自:http://www.cnblogs.com/leonbao/archive/2008/03/07/1094821.html
关于SQL Server数据库设计的感悟,请指教
有问题的时候,我经常回来博客园寻找答案,久而久之,总结了一些东西。
妄自菲薄,请大家多指出错误,并给出意见
数据库设计三范式基本原则
第一范式:数据库表中的字段都是单一属性的,不可再分。这 ......

SQL 如何删除数据表中重复的数据?

【引用:猛犸技术文章摘要

经测试,方法二可成功删除数据,方法一、三 删除数据失败。请路过的朋友,指点迷津。。。
问题:一个表有自增的ID
列,表中有一些记录内容重复,也就是说这些记录除了ID
不同之外,其他的信息都相同。需要把重复的记录保留一条,剩下的删除
 
方法一:还是2000
年的时候一位Oracl ......

sql server 判断表/视图/存储过程是否存在

--如果是实表可以用
if exists (select * from sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[表名]
--如果是临时表可以用(说明,如果用查找实表方法来打临时表会找不到.发布区别对代.)
if object_id('tempdb..##temp') is not null
   ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号