Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL Server 2005 T SQL cross Apply Óëouter apply

SQL Server 2005 T-SQL Apply
͸¹ýÖ´Ðмƻ®¿ÉÒÔ¿´³ö£¬cross applyÀàËƲ»´øwhereÌõ¼þµÄÁ¬½Ó¼´cross join £¨½»²æÁ¬½Ó¼´µÑ¿¨¶û»ý£º·µ»ØÐÐÊýΪ£ºÇ°±í·ûºÏÌõ¼þµÄÐгËÉϺó±í·ûºÏÌõ¼þµÄÐУ© ¡£ÐÎʽÉÏ»áÁé»îЩ.
ʹÓà APPLY ÔËËã·û¿ÉÒÔΪʵÏÖ²éѯ²Ù×÷µÄÍⲿ±í±í´ïʽ·µ»ØµÄÿ¸öÐе÷ÓñíÖµº¯Êý¡£±íÖµº¯Êý×÷ΪÓÒÊäÈ룬Íⲿ±í±í´ïʽ×÷Ϊ×óÊäÈë
¡£Í¨¹ý¶ÔÓÒÊäÈëÇóÖµÀ´»ñµÃ×óÊäÈëÿһÐеļÆËã½á¹û£¬Éú³ÉµÄÐб»×éºÏÆðÀ´×÷Ϊ×îÖÕÊä³ö¡£APPLY ÔËËã·ûÉú³ÉµÄÁеÄÁбíÊÇ×óÊäÈëÖÐ
µÄÁм¯£¬ºó¸úÓÒÊäÈë·µ»ØµÄÁеÄÁÐ±í¡£
APPLY ÓÐÁ½ÖÖÐÎʽ£º CROSS APPLY ºÍ OUTER APPLY¡£CROSS APPLY ½ö·µ»ØÍⲿ±íÖÐͨ¹ý±íÖµº¯ÊýÉú³É½á¹û¼¯µÄÐС£OUTER APPLY ¼È·µ
»ØÉú³É½á¹û¼¯µÄÐУ¬Ò²·µ»Ø²»Éú³É½á¹û¼¯µÄÐУ¬ÆäÖбíÖµº¯ÊýÉú³ÉµÄÁÐÖеÄֵΪ NULL¡£
ÀýÈ磬¿¼ÂÇÏÂÁбí Employees ºÍ Departments£º
 ¸´ÖÆ´úÂë
--Create Employees table and insert values
CREATE TABLE Employees
(
  empid   int         NOT NULL,
  mgrid   int         NULL,
  empname varchar(25) NOT NULL,
  salary  money       NOT NULL,
  CONSTRAINT PK_Employees PRIMARY KEY(empid),
)
GO
INSERT INTO Employees VALUES(1 , NULL, 'Nancy'   , $10000.00)
INSERT INTO Employees VALUES(2 , 1   , 'Andrew'  , $5000.00)
INSERT INTO Employees VALUES(3 , 1   , 'Janet'   , $5000.00)
INSERT INTO Employees VALUES(4 , 1   , 'Margaret', $5000.00)
INSERT INTO Employees VALUES(5 , 2   , 'Steven'  , $2500.00)
INSERT INTO Employees VALUES(6 , 2   , 'Michael' , $2500.00)
INSERT INTO Employees VALUES(7 , 3   , 'Robert'  , $2500.00)
INSERT INTO Employees VALUES(8 , 3   , 'Laura'   , $2500.00)
INSERT INTO Employees VALUES(9 , 3   , 'Ann'     , $2500.00)
INSERT INTO Employees VALUES(10, 4   , 'Ina'     , $2500.00)
INSERT INTO Employees VALUES(11, 7   , 'David' 


Ïà¹ØÎĵµ£º

MS SQL ²éѯÁª½ÓÔËËãϵÁУ­£­¹þÏ£Áª½Ó£¨Hash Join)

¹þÏ£Áª½ÓÊǵÚÈýÖÖÎïÀíÁª½ÓÔËËã·û£¬µ±Ëµµ½¹þÏ£Áª½Óʱ£¬ËüÊÇÈýÖÖÁª½ÓÔËËãÖÐÐÔÄÜ×îºÃµÄ£®Ç¶Ì×Ñ­»·Áª½ÓÊÊÓÃÓÚÏà¶Ô½ÏСµÄÊý¾Ý¼¯£¬¶øºÏ²¢Áª½ÓÊÊÓÃÓÚÖеȹæÄ£µÄÊý¾Ý¼¯£¬¶ø¹þÏ£Áª½ÓÔòÊÊÓÃÓÚ´ó¹æÄ£Áª½ÓµÄÊý¾Ý¼¯£®
¹þÏ£Áª½ÓËã·¨²ÉÓ㢹¹½¨£¢ºÍ£¢Ì½²â£¢Á½²½À´Ö´ÐУ®ÔÚ£¢¹¹½¨£¢½×¶Î£¬ËüÊ×ÏÈ´ÓµÚÒ»¸öÊäÈëÖжÁÈ¡ËùÓÐÐУ¨³£½Ð×ö×ó»ò¹¹½¨Ê ......

sql server ×Ö·û´®´¦Àíº¯Êý

ÎÒÃÇÕâÀï¶Ô SQL Server ×Ö·û´®º¯Êý½øÐзÖÃűðÀàµØÁгö£¬±ãÓÚ²éÔĺͼÇÒ䣬ÏàÐÅ´ó¼Ò¶¼ÔÚÆäËü·½ÃæÓиßÉîµÄ±à³Ì»ù´¡£¬´Ó×ÖÃæÉÏÀ´Ëµ´ó¼Ò¶¼ÖªµÀÕâЩº¯ÊýµÄÒâÒ壬¾Í²»¶ÔÕâЩº¯Êý×÷¹ý¶àµÄ½âÊÍÁË£¬Ö÷Ҫ̸Щ¾­Ñ飬¾ßÌåÇë²Î¼ûÁª»ú´ÔÊé¡£
ASCII(character_expression) ·µ»Ø×î×ó¶Ë×Ö·ûµÄ ASCII ´úÂëÖµ
CHAR(integer_expression)
UNICO ......

Sqlº¯Êý´óÈ«

--¾ÛºÏº¯Êý
use pubs
go
select avg(distinct price)  --Ëãƽ¾ùÊý
from titles
where type='business'
go
use pubs
go
select max(ytd_sales)  --×î´óÊý
from titles
go
use pubs
go
select min(ytd_sales) --×îСÊý
from titles
go
use pubs
go
select type,sum(price),sum(advance)  ......

Sql server 2005 µÇ¼ɨä

1.       ÔÚʹÓÃsql server ֮ǰÄØ£¬×îºÃ¶ÔÆä½øÐÐÅäÖÃ
(1)  ÅäÖù¤¾ß->Sql server configuration Manager  
        Ñ¡ÔñSql server 2005Íø·ÅäÖà Ï嵀 MSSQLSERVERµÄЭÒé ÔÚ´°¿ÚÓұߵÄ
TCP/IPЭÒéÓÒ¼üÊôÐÔ£¬ÅäÖÃÈçÏÂ
 
&n ......

Excelµ¼ÈëSQLÊý¾Ý¿â³öÏÖµÄÎÊÌ⡾½â¾ö¡¿

¡¾ÎÊÌâÒ»
¡¿£ºÒѾܾø¶Ô OLE DB Ìṩ³ÌÐò 'MICROSOFT.JET.OLEDB.4.0' µÄÌØÊâ·ÃÎÊ¡£±ØÐëͨ¹ýÁ´½Ó·þÎñÆ÷À´·ÃÎÊ´ËÌṩ³ÌÐò¡£
¡¾·ÖÎö
¡¿£ºÕâÊÇÒòΪÄúµ±Ç°ÓÃÀ´·ÃÎÊÊý¾Ý¿âµÄµÇ¼µÄȨÏÞ²»¹»£¨È¨ÏÞÌ«µÍ£©¡£
¡¾½â¾ö
¡¿£ºÒªÃ´Äú»¹ÓÃsaµÇ¼£¬ÒªÃ´Ð޸ĵ±Ç°µÇ¼µÄȨÏÞ£¬²½ÖèÈçÏ£ºÆóÒµ¹ÜÀíÆ÷→°²È«ÐÔ→µÇ¼→ÕÒµ½ÄãËùÓõ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ