1、使用雙引號
select count(*) "總數" from table;
2、使用單引號
select count(*) '總數' from table;
3、直接加別名,用空格隔開
select count(*) zongshu from table;
4、使用as關鍵字連接
select count(*) as zongshu from table;
5、使用=號連接(sqlserver使用)
select count(*) =zongshu from table;
注意事項
當我們使用某個表達式作為輸出的一列時,我們無法再Where條件中直接使用該列作判斷條件.
例如下面的SQL語句:
select id, (c1 + c2) as s from t1 where s > 100 SQL Server 報錯: "列名 s 無效"
使用以下語句即可
select t2.* from (select id, (c1 + c2) as c from t1) t2 where c > 100 --或者 select t2.* from (select id, c = c1+c2 from t1) t2 where c > 100
SELECT 語句的執行順序 1. from語句 2. where語句(結合條件) 3. start with語句 4. connect by語句 5. where語句 6. group by語句 7. having語句 8. model語句 9. select語句 10. union、minus、intersect等集合演算演算 11. order by語句