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

SQL SERVER 2005 ¸ß¼¶²éѯ£¨×Ó²éѯ²éѯ£©

--SQL¸ß¼¶³ÌÐòÉè¼Æ£º×Ó²éѯ
use AdventureWorks
GO
SELECT DISTINCT EmployeeID from HumanResources.JobCandidate WHERE EmployeeID IS NOT NULL;
SELECT e.EmployeeID,FirstName,LastName
from HumanResources.Employee e
INNER JOIN Person.Contact c
 ON e.ContactID = c.ContactID
WHERE e.EmployeeID IN (SELECT DISTINCT EmployeeID from HumanResources.JobCandidate
      WHERE EmployeeID IS NOT NULL)
SELECT DISTINCT EmployeeID from HumanResources.JobCandidate WHERE EmployeeID IS NOT NULL
SELECT e.EmployeeID,FirstName,LastName
from HumanResources.Employee e
INNER JOIN Person.Contact c
 ON e.ContactID = c.ContactID
WHERE e.EmployeeID NOT IN (
       SELECT DISTINCT EmployeeID
       from HumanResources.JobCandidate
       WHERE EmployeeID IS NOT NULL
       )
SELECT CustomerID,MIN((OrderDate)) AS OrderDate
INTO #MinOrderDates
from Sales.SalesOrderHeader
GROUP BY CustomerID
ORDER BY CustomerID
SELECT o.CustomerID,o.SalesOrderID,o.OrderDate
from Sales.SalesOrderHeader o
inner join #MinOrderDates t
 on o.CustomerID = t.CustomerID
 and o.OrderDate = t.OrderDate
order by o.CustomerID
DROP TABLE #MinOrderHeaders
SELECT O1.CustomerID,o1.SalesOrderID,o1.OrderDate
from Sales.SalesOrderHeader o1
WHERE o1.OrderDate = (SELECT MIN(o2.OrderDate)
      from Sales.SalesOrderHeader o2
      WHERE O2.CustomerID = o1.CustomerID)
ORDER BY CustomerID
SELECT c.LastName,ISNULL(CAST((SELECT MIN(OrderDate) from Sales.SalesOrderHeader o
     WHERE o.ContactID = c.ContactID) AS VARCHAR),'NEVER RECORD') AS "Order Date"
from Person.Contact c
SELECT e.EmployeeID,FirstName,LastName
from HumanResources.Employee e
INNER JOIN Person.Contact c
 ON e.ContactID = c.ContactID
WHERE EXISTS(SELECT DISTI


Ïà¹ØÎĵµ£º

Excel´ò¿ª´ÓPL/SQL Deleveloperµ¼³öµÄcsvÎļþÂÒÂëÎÊÌâ

ÓÃPL/SQL Deleveloperµ¼³öcsvÎļþ¸ñʽÊý¾Ý£¬ÓÃexcel´ò¿ªÊÇÂÒÂ룬ÓüÇʱ¾´ò¿ªÕý³££¬Ôõô»ØÊ£¿
ÂíÉÏGoogle£¬Ô­À´µ¼³öµÄÎļþµÄ±àÂë¸ñʽÊÇUTF-8ºÍ¶øexcelĬÈÏ´ò¿ªÎļþµÄ±àÂëÊÇunicode£¬ÓÚÊÇ£º
1¡¢ÓüÇʱ¾´ò¿ªÎļþ£¬È»ºóÁí´æΪ£¬ÌîдÎļþÃû£¬Ñ¡Ôñ±àÂë¸ñʽΪunicode
2¡¢ÓÃexcel´ò¿ªÐµÄÎļþ£¬Õý³£ÏÔʾ
µ«ÊdzöÏÖÁíÍâµÄÎÊÌ⣠......

sqlÓï¾äÓÅ»¯2

£¨18£©ÓÃEXISTSÌæ»»DISTINCT£º
µ±Ìá½»Ò»¸ö°üº¬Ò»¶Ô¶à±íÐÅÏ¢(±ÈÈ粿ÃűíºÍ¹ÍÔ±±í)µÄ²éѯʱ,±ÜÃâÔÚSELECT×Ó¾äÖÐʹÓÃDISTINCT¡£Ò»°ã¿ÉÒÔ¿¼ÂÇÓÃEXISTÌæ»», EXISTS Ê¹²éѯ¸üΪѸËÙ,ÒòΪRDBMSºËÐÄÄ£¿é½«ÔÚ×Ó²éѯµÄÌõ¼þÒ»µ©Âú×ãºó,Á¢¿Ì·µ»Ø½á¹û¡£Àý×Ó£º
(µÍЧ):
SELECT DISTINCT DEPT_NO,DEPT_NAME  ......

¶Á¡¶SQL Server 2005¸ß¼¶¹ÜÀí¡·µÄһЩժҪ... Á¬ÔØ5

ÔÚT-SQLÖмàÊÓ½ø³Ì
DBA¸üÔ¸ÒâʹÓÃT-SQLµÄÔ­ÒòÊÇ¿ÉÒԱȓ»î¶¯¼àÊÓÆ÷”¸ü¼ÓÁé»îµØ»ñµÃÐÅÏ¢¡£
1.       sp_whoºÍsp_who2
´æ´¢¹ý³Ìsp_whoÒ²·µ»Øµ±Ç°Á¬½ÓÊý¾Ý¿âʵÀý£¬Ó듻¼àÊÓÆ÷”·Ç³£ÀàËÆ¡£È»¶ø£¬Óû§¿ÉÄÜ·¢ÏÖ×Ô¼º¸üÔ¸ÒâʹÓÃδ¹«¿ªËµÃ÷µÄsp_who2´æ´¢¹ý³Ì£¬ÒòΪËüÌṩ ......

Ò»¸ösql¼òµ¥º¯ÊýʵÏÖÆ´½Ó×Ö·û´®

--²âÊÔÊý¾Ý
create table table1(AID int,NAME nvarchar(20))
create table table2 (BID int,NUMBER nvarchar(20))
insert into table1 select 1,'Tom' union all
select 2,'Jim'
insert into table2 select 1,20 union all
select 1,30
--º¯Êý
create function F_Str(@ID int)
returns nvarchar(100)
as
begin ......

SQL Á¬½Ó×Ö·û´®µÄ˵Ã÷


ת×Ô£ºhttp://hi.baidu.com/arslong/blog/item/b23307e76252342cb8382001.html
Item01
Á¬½Ó×Ö·û´®Öг£ÓõÄÉùÃ÷ÓУº
·þÎñÆ÷ÉùÃ÷£ºData Source
¡¢Server
ºÍAddr
µÈ¡£
Êý¾Ý¿âÉùÃ÷£ºInitial Catalog
ºÍDataBase
µÈ¡£
¼¯³ÉWindows
Õ˺ŵݲȫÐÔÉùÃ÷£ºIntegrated
Security
ºÍTrusted_Connection
µÈ¡£
ʹÓÃÊý¾Ý¿â ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ