SQL Aliases (AS) 別名
SQL別名用於給欄位別名及表格別名中,指定一個臨時名稱。別名通常用於使列名更易讀。在查詢期間僅存在別名。分成一列或多列。
欄位別名:SELECT '欄位A','欄位B' AS 別名 FROM 資料表;
表格別名:SELECT '欄位A','欄位 B' FROM 資料表 AS 別名;
SELECT CustomerID AS ID, CompanyName AS Name,Country FROM Customers ;
CustomerID |
CompanyName |
Country |
1 |
Alfreds Futterkiste |
Germany |
2 |
Ana Trujillo Emparedados y helados |
Mexico |
3 |
Antonio Moreno Taqueria |
Mexico |
4 |
Around the Horn |
UK |
5 |
Berglunds snabbkop |
Sweden |
6 |
Blauer See Delikatessen |
Germany |
7 |
Blondesddsl pere et fils |
France |
8 |
Bolido Comidas preparadas |
Spain |
9 |
Bon app' |
France |
10 |
Bottom-Dollar Markets |
Canada |
11 |
Du monde entier |
France |
結果:
ID |
Name |
Country |
1 |
Alfreds Futterkiste |
Germany |
2 |
Ana Trujillo Emparedados y helados |
Mexico |
3 |
Antonio Moreno Taqueria |
Mexico |
4 |
Around the Horn |
UK |
5 |
Berglunds snabbkop |
Sweden |
6 |
Blauer See Delikatessen |
Germany |
7 |
Blondesddsl pere et fils |
France |
8 |
Bolido Comidas preparadas |
Spain |
9 |
Bon app' |
France |
10 |
Bottom-Dollar Markets |
Canada |
11 |
Du monde entier |
France |