- 選擇語法使用like
SELECT * FROM Customers WHERE City LIKE '%s' ; // %代表0個或多個字符,且以s為結尾的資料列
SELECT * FROM Customers WHERE City LIKE '_owes' // _ 代表1 ,且以s為結尾的資料列
SELECT * FROM Customers WHERE City LIKE '[bsp]%' // 代表以b 或s或p開始之資料列 SELECT * FROM Customers WHERE City LIKE '[a-c]%'; // a-c開始之資料列
SELECT * FROM Customers WHERE City NOT LIKE '[bsp]%'; // 加上NOT - IN語法 - 在where語句內一次取得多個條件
SELECT * FROM Customers WHERE City IN ('Paris' , 'Landon')
- BETWEEN 語法 - 在where語句內可以選擇一個range 的值
- // 選擇Price 在10~20內且CategoryID != 1,2,3
SELECT * FROM Products WHERE (Price BETWEEN 10 AND 20) AND NOT CategoryID IN (1,2,3) - //日期也可以使用
SELECT * FROM Orders WHERE OrderDate BETWEEN #07/04/1996# AND #07/09/1996#;
- Alisase 用來暫時給予Table 或是 Column別名
//分別賦予Column ,Table 別名 ,當別名有空白建的時候則要加上[ ]
SELECT CustomerName AS Customer, ContactName AS [Contact Person] FROM Customers; - //選擇CustomerName 和 Adress(由多欄位串接而成並賦予其別名)
SELECT CustomerName, Address+','+City+','+PostalCode+','+Country AS Adress FROM Customers
- //使用"別名" 在相同的ID下從兩個不同資料表中取出特定的資料 使其更易於閱讀
SELECT o.OrderID, o.OrderDate, c.CustomerName
FROM Customers AS c, Orders AS o
WHERE c.CustomerName="Around the Horn" AND c.CustomerID=o.CustomerID;
文章標籤
全站熱搜
