資料庫中為查詢結果的列起別名

2021-08-25 02:25:42 字數 920 閱讀 9007

利用as為查詢的列起別名,並沒有真正改變資料庫表中列的名稱,只是為了方便檢視

1.利用as關鍵字

select tsid as 學生編號,tsname as 學生姓名,tsgender as 性別 from tblstudent

2.第二種寫法as

select

tsid as 學生編號,

tsname as 學生姓名,

tsgender as 性別

from tblstudent

3.省略關鍵字as

select                 

tsid 學生編號,

tsname 學生姓名,

tsgender 性別

from tblstudent

4.如果列名中包含小括號等非法字元,用引號 引起來

select                 

tsid    '(學生編號)',

tsname   學生姓名,

tsgender 性別

from tblstudent

5.把列名放前面使用=號

select                 

學生編號 = tsid , 

學生姓名 = tsname,

性別 = tsgender

from tblstudent

6.可以給資料表中加乙個新的列名,新加一列

select                 

學生編號 = tsid , 

學生姓名 = tsname,

性別 = tsgender,

'婚否' = 否   --新加婚否一列 列中的內容全為否,如果用as替換為=則 '婚否' = 否寫法順序相反

from tblstudent

PHP中把資料庫查詢結果輸出為json格式簡單例項

include conn.php為資料庫鏈結檔案,不會的網上搜尋 sql notice mysql query select from gg notice where enable 1 limit 0,10 notice mysql fetch array sql notice,mysql asso...

資料庫表和列的別名的用法

使用資料庫別名可以讓sql語句的可讀性更強 1 怎麼給資料庫表和某列 字段 起別名 用as就可以 列的別名 sql select 列名 as 別名 from 表名 表的別名 sql select 列名 from 表名 as 別名 2 怎麼使用 假設info表中三個字段 name age 我們可以使用...

JDBC查詢資料時列別名的問題

在使用jdbc過程中,要經常使用表連線的sql語句,2個表的重疊字段,就不可避免的要使用字段別名,如下情況 select t1.tid,t2.tid from table1 t1,table2 t2 where t1.tid t2.tid 如果僅僅這樣寫,在接下來,使用結果集獲取資料時,悲劇就發生了...