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 )
Ïà¹ØÎĵµ£º
Ñ¡Ôñ×Ô CSDN
SQLÓï¾äµ¼Èëµ¼³ö´óÈ«
/******* µ¼³öµ½excel
EXEC master..xp_cmdshell 'bcp SettleDB.dbo.shanghu out c:\temp1.xls -c -q -S"GNETDATA/GNETDATA" -U"sa" -P""'
/*********** µ¼ÈëExcel
SELECT *
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\tes ......
Microsoft SQL Server
2008ºÍMicrosoftÊý¾Ýƽ̨Ϊ¿ª·¢ÈËÔ±ÌṩÁËÒ»¸ö×ۺϵıà³Ì¼Ü¹¹£¬ÓÃÓÚ´´½¨Õë¶ÔÒÆ¶¯É豸¡¢×ÀÃæµçÄÔ¡¢Web·þÎñÆ÷£¬ºÍÆóÒµ·þÎñÆ÷µÄ»ùÓÚÊý¾ÝµÄ½â
¾ö·½°¸¡£Õâ¸öÊý¾Ý±à³Ì»·¾³½«Êý¾Ý·ÃÎʺ͹ÜÀí¼¯³Éµ½Ò»¸öÓ¦ÓóÌÐòµÄÒµÎñÂß¼ÖУ¬´Ó¶øÌá¸ßÁË¿ª·¢ÈËÔ±µÄÉú²úÁ¦¡£ËüÌṩÁËÒ»¸öÓÃÓÚ¶ÔÒì¹¹Êý¾ÝÔ´µÄÊý¾Ý·ÃÎʺ͹ÜÀí
µÄ ......
SQL ServerÀïµÄ ISNULL Óë Oracle ÖÐµÄ NULLIF²»Í¬:
SQL Server ÖÐÓÐÁ½¸ö²ÎÊý£¬Óï·¨£º
ISNULL(check_expression, replacement_value)
check_expression Óë replacement_value Êý¾ÝÀàÐͱØÐëÒ»ÖÂ
Èç¹û check_expression Ϊ NULL£¬Ôò·µ»Ø replacement_v ......
¡¾IT168 ¼¼Êõ·ÖÎö¡¿ÔÚÏò2009Äê¸æ±ðÖ®¼Ê£¬ÎÒÃÇÀ´»Ø¹ËһϹýÈ¥µÄÒ»ÄêÖÐ×îÊÜ»¶ÓµÄSQL Server¼¼ÇÉ£¬°üÀ¨ÁËOPENROWSET¡¢FILESTREAMµÈº¯ÊýµÄÓ÷¨¡¢ÃÜÂ빤¾ß½éÉÜÒÔ¼°DBAÈÕ³£¹¤×÷½¨ÒéµÈÄÚÈÝ¡£
¡¡¡¡Í¨¹ý¶ÔÕâЩ¾«»ªÎÄÕµÄÔٴλعˣ¬Ï£Íû¿ÉÒÔ°ïÖúÄúÊáÀíÒ»ÏÂÕâÒ»ÄêÒÔÀ´µÄ¹¤×÷ÒÔ¼°Ñ§Ï°Ðĵ㬶ÔδÀ´Ò»Äê¸ü½øÒ»²½´òϸü¼áʵµÄ»ù´¡¡£
¡¡¡ ......