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
Ïà¹ØÎĵµ£º
1.Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)¡¡¡¡
¡¡¡¡ SQLSERVERµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬Òò´Ëfrom×Ó¾äÖÐдÔÚ×îºóµÄ±í£¨»ù´¡±ídriving table£©½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏ£¬±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í£¬µ±SQLSERVER´¦Àí¶à¸ö±íʱ£¬»áÔËÓÃÅÅÐò¼°ºÏ²¢µÄ·½Ê½Á ......
Èç¹ûÄã¾³£Óöµ½ÏÂÃæµÄÎÊÌ⣬Äã¾ÍÒª¿¼ÂÇʹÓÃSQL ServerµÄÄ£°åÀ´Ð´¹æ·¶µÄSQLÓï¾äÁË£º
SQL³õѧÕß¡£
¾³£Íü¼Ç³£ÓõÄDML»òÊÇDDL SQL Óï¾ä¡£
ÔÚ¶àÈË¿ª·¢Î¬»¤µÄSQLÖУ¬Ã¿¸öÈ˶¼ÓÐ×Ô¼ºµÄSQLϰ¹ß£¬Ã»ÓÐÒ»Ì×ͳһµÄ¹æ·¶¡£
ÔÚSQL Server Management StudioÖУ¬ÒѾ¸ø´ó¼ÒÌṩÁ˺ܶೣÓõÄÏÖ³ÉSQL¹æ·¶Ä£°å¡£
SQL Server Management ......
µÍЧ: (Ë÷ÒýʧЧ)
SELECT … from DEPARTMENT WHERE DEPT_CODE IS NOT NULL;
¸ßЧ: (Ë÷ÒýÓÐЧ)
SELECT … from DEPARTMENT WHERE DEPT_CODE >=0;
£¨27£©×ÜÊÇʹÓÃË÷ÒýµÄµÚÒ»¸öÁУº
Èç¹ûË÷ÒýÊǽ¨Á¢ÔÚ¶à ......
Õª×Ôhttp://blog.sina.com.cn/zhm85
SQLÓï¾ä½ØÈ¡Ê±¼ä£¬Ö»ÏÔʾÄêÔÂÈÕ£¨2004-09-12£©
select CONVERT(varchar, getdate(), 120 )
‘getdate£¨£©’¸ÄΪʱ¼ä×Ö¶ÎÃû‘createtime’
ÔÙÖØÃüÃûмÓÁУ¨Select Name AS UName from Users£©
ÀýÈç select convert(varchar(11),createtime,120) as Ndate fro ......
ת×Ô£ºhttp://hi.baidu.com/arslong/blog/item/b23307e76252342cb8382001.html
Item01
Á¬½Ó×Ö·û´®Öг£ÓõÄÉùÃ÷ÓУº
·þÎñÆ÷ÉùÃ÷£ºData Source
¡¢Server
ºÍAddr
µÈ¡£
Êý¾Ý¿âÉùÃ÷£ºInitial Catalog
ºÍDataBase
µÈ¡£
¼¯³ÉWindows
Õ˺ŵݲȫÐÔÉùÃ÷£ºIntegrated
Security
ºÍTrusted_Connection
µÈ¡£
ʹÓÃÊý¾Ý¿â ......