SELECT語句的格式

SELECT [ALL | DISTINCT 列1,列2 ] FROM 表1,表2 ] [WHERE“條件”] [GROUP BY“列清單”] [“條件] [ORDER BY”列清單“[ASC | DESC] ]
Comparison Operators

= Equal 等於
> Greater than 大於
< Less than 小於
>= Greater than or equal to 大於或等於
<= Less than or equal to 小於或等於
<> Not equal to 不等於
LIKE String comparison test 包含
使用like例句: SELECT name, title, dept FROM employee WHERE title LIKE 'Pro%';

ORDER BY練習
一般 Select
1. 選擇 items_ordered 資料表中的所有欄位
2. 選擇 items_ordered 資料表中的customerid 及item
3. 選擇 items_ordered 資料表中的customerid ,item,quantity及price


按條件的Select 利用 LIKE
1. 選擇 items_ordered 資料表中的customerid ,item,及price,其CustomerID為 10449
2. 選擇 items_ordered 資料表中購買了item為Tent的customerid 及item
3. 選擇 items_ordered 資料表中購買了item為Tent或Umbrella的customerid 及item

--------------------包含某些字 ,使用like---------------------
4. 選擇 items_ordered 資料表中item為以字母“S”開始的所有資料
5. 選擇 items_ordered 資料表中item為以字母“t”結尾的customerid ,item及price
6. 選擇 items_ordered 資料表中item為以字母中包含“o”的item及price

--------------------範圍-----------------------
7. 選擇 items_ordered 資料表中price高於30的item及price
8. 選擇 items_ordered 資料表中price小於50的item及price


按條件的Select 利用AND, OR, IN, BETWEEN..AND, *(萬用字元), LIKE

------------------AND, OR, <>-------------------
1. 選擇 items_ordered 資料表中item為Unicycle或Umbrella的customerid 及item
2. 選擇 items_ordered 資料表中價錢為$10至$40的item及price
3. 選擇 items_ordered 資料表中價錢為$10至$40,或大於$60的item及price
4. 選擇 items_ordered 資料表中item不等於Unicycle的item
5. 選擇 items_ordered 資料表中item為Unicycle,Umbrella以外的item及price

------------------IN, BETWEEN...AND-------------------
6. 選擇 items_ordered 資料表中item為Unicycle,Umbrella, Pillow, Helmet的所有資料
7. 選擇 items_ordered 資料表中item的訂購日期為'1-Dec-1999' 至 '18-Jan-2000'
8. 選擇 items_ordered 資料表中價錢為$10至$40的item及price


按條件的Select 利用 AVG(), COUNT(), MAX(), MIN(), SUM()

1a. 計算 items_ordered 資料表中所有物品的平均價錢
1b. 計算 items_ordered 資料表中所有物品的平均數量
2. 計算 items_ordered 資料表中物品Umbrellaff的平均價錢
3a. 數算 items_ordered 資料表中customerid為10101的數目
3b. 數算 items_ordered 資料表中數量為2的物品數目

4. 找出 items_ordered 資料表中最貴物品的價錢
5a. 找出 items_ordered 資料表中最貴物品的customerid, item及price
5b. 找出 items_ordered 資料表中最貴的 Tent 的customerid, item及price

6. 找出 items_ordered 資料表中最平物品的價錢
7. 找出 items_ordered 資料表中最平物品的customerid, item及price
8a. 找出 items_ordered 資料表中所有的 Tent 的總費用
8b. 找出 items_ordered 資料表中所有記錄的總費用

-------------------------AS, DISTINCT, GROUPBY
9. 找出 items_ordered 資料表中所有customerid (不能重複)
10a. 找出 items_ordered 資料表中以item分組的總費用,顯示item及總費用
10b. 找出 items_ordered 資料表中以item分組的平均價錢,顯示item及平均價錢


挑戰題
找出 items_ordered 資料表中以item分組的總費用,顯示item及總費用,數量為1,並以item由大至小排列