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
Ïà¹ØÎĵµ£º
l INNER JOIN
ÄÚÁ¬½ÓÊÇ×î³£¼ûµÄÒ»ÖÖÁ¬½Ó£¬ËüÒ³±»³ÆÎªÆÕͨÁ¬½Ó£¬¶øE.FCodd×îÔç³ÆÖ®Îª×ÔÈ»Á¬½Ó¡£
ÏÂÃæÊÇANSI SQL£92±ê×¼
select * from t_institution i
inner join t_teller t
on i.inst_no = t.inst_no //˵Á½¸ö±íÖ®¼äµÄ¹ØÏµÓÃON
where i.inst_no = "5801"
ÆäÖÐinner¿ÉÒÔʡ ......
l ÔÚ³ÌÐòÖÐÆ´½ÓSQLÃüÁî
¿ÉÊÇÈçºÎÔÚC#³ÌÐòÖÐÔËÐÐÄØ£¿ÎÒÃǼǵÃÔÚÆÕͨµÄSQL²éѯÖУ¬Ò»°ãÐèÒª°Ñ²éѯÓï¾ä¸³Öµ¸øSalCommand.CommandTextÊôÐÔ£¬ÕâÀïÒ²¾ÍÏñÆÕͨµÄSQL²éѯÓï¾äÒ»Ñù£¬½«ÕâЩÓï¾ä¸³¸øSqlCommand.CommandTextÊôÐÔ¼´¿É¡£Òª×¢ÒâµÄÒ»µãÊÇ£¬ÆäÖеÄ"GO"Óï¾ä±êÖ¾×ÅSQLÅú´¦ÀíµÄ½áÊø£¬±àдSQL½Å±¾ÊÇÐèÒªµÄ£¬µ«ÊÇÔÚÕâÀïÊDz ......
use AdventureWorks
GO
SELECT c.LastName from Person.Contact c;
SELECT * from HumanResources.Employee e
INNER JOIN HumanResources.Employee m
ON e.ManagerID = m.EmployeeID; n
SELECT ProductID,Name,ProductNumber,ReorderPoint
from Production.Product
where ProductID in( select ProductID fro ......