易截截图软件、单文件、免安装、纯绿色、仅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的分类汇总
SQL SERVER中使用GROUP BY对数据进行分类汇总,我们也可以使用WITH ROLLUP和WITH CUBE配合GROUP BY进行“增强”了的分类汇总,那么他们两个是如何增强GROUP BY的汇总能力的呢?
一.功能增强
1.使用WITH ROLLUP
用下面的例子说明,GROUP使用了3个分组字段:GROUP BY A, B, C WITH ROLLUP ......

sql server日期时间函数

Sql Server中的日期与时间函数
1.  当前系统日期、时间
    select getdate() 
2. dateadd  在向指定日期加上一段时间的基础上,返回新的 datetime 值
   例如:向日期加上2天
   select dateadd(day,2,'2004-10-15')  --返回:2004-10-17 00:00:00.000 ......

使用SQL Server导入/导出Excel

使用SQL Server导入/导出Excel,包含部分错误信息处理方法;
操作手记,留此备查
/*
导入
*/
--错误信息如下时:
--Msg 15281, Level 16, State 1, Line 2
--SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as ......

通过v$sqlarea,v$sql查询最占用资源的查询

通过v$sqlarea,v$sql查询最占用资源的查询 收藏
 引用:http://blog.chinaunix.net/u/3866/showart_396335.html
-----------------------
v$sqlarea,v$sql
-----------------------
从V$SQLAREA中查询最占用资源的查询
select b.username username,a.disk_reads reads,
    a.executions exec,a ......

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号