Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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µÄÐÐÁÐת»»¹¦Äܷdz£ÊµÓ㬵«ÊÇÓÉÓÚÆäÓï·¨²»ºÃ¶®£¬Ê¹ºÜ¶à³õѧÕß¶¼²»Ô¸ÒâʹÓÃËü¡£ÏÂÃæÎÒ¾ÍÓÃʾÀýµÄÐÎʽ£¬ÖðÒ»Õ¹ÏÖPivotºÍUnPivotµÄ÷ÈÁ¦¡£ÈçÏÂͼ
 
1.´ÓWide Table of Months ת»»µ½ Narrow TableµÄʾÀý
select [Year],[Month],[Sales] from
(
select * from MonthsTable
)p
unpivot
(
[Sales] for ......

SQL Server 2008 ¾«ÃîÖ®´¦

±¾ÎĽéÉÜÁËSQL Server 2008ÀïһЩеÄÌØµãÒÔ¼°·¢ÏÖµÄһЩ¾«ÃîÖ®´¦……
¡¡¡¡°²×°
¡¡¡¡SQL
Server
2008µÄÉèÖúͰ²×°Ò²ÓÐËù¸Ä½ø¡£ÅäÖÃÊý¾ÝºÍÒýÇæÎ»ÒѾ­·Ö¿ªÁË£¬ËùÒÔËüʹ´´½¨»ù±¾µÄδÅäÖÃϵͳµÄ´ÅÅÌͼÏñ±äµÃ¿ÉÄÜÁË£¬Ëüʹ·Ö²¼µ½¶à¸ö·þÎñÆ÷±äµÃ¸üÈÝÒ×ÁË¡£
´Ó΢ÈíµÄÕ¾µãÒ²¿ÉÒÔÕÒµ½°²×°¿ÉÓõÄ×îиüС£ÁíÒ»¸öÌØµ ......

ʹÓÃ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×îÊÜ»¶Ó­¼¼ÇÉ:½â¶ÁDBA

¡¾IT168 ¼¼Êõ·ÖÎö¡¿ÔÚÏò2009Äê¸æ±ðÖ®¼Ê£¬ÎÒÃÇÀ´»Ø¹ËһϹýÈ¥µÄÒ»ÄêÖÐ×îÊÜ»¶Ó­µÄSQL Server¼¼ÇÉ£¬°üÀ¨ÁËOPENROWSET¡¢FILESTREAMµÈº¯ÊýµÄÓ÷¨¡¢ÃÜÂ빤¾ß½éÉÜÒÔ¼°DBAÈÕ³£¹¤×÷½¨ÒéµÈÄÚÈÝ¡£
¡¡¡¡Í¨¹ý¶ÔÕâЩ¾«»ªÎÄÕµÄÔٴλعˣ¬Ï£Íû¿ÉÒÔ°ïÖúÄúÊáÀíÒ»ÏÂÕâÒ»ÄêÒÔÀ´µÄ¹¤×÷ÒÔ¼°Ñ§Ï°Ðĵ㬶ÔδÀ´Ò»Äê¸ü½øÒ»²½´òϸü¼áʵµÄ»ù´¡¡£
¡¡¡ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ