-
計算字段
重新格式化
備註:計算字段不真實存在數據庫表中,是在運行select語句是創建的表 -
拼接字段——concat(字段1,字段2,…)
select concat (字段1,字段2) from 表
select concat (id ,name) from user;
直接拼接:id名字
select concat (id,'(',name,')") from user;
拼接:id(名字),name用()括起來:(備註共拼接了4個字符"id","(","name",")")
- 使用別名—— as 別名
select concat (字段1,字段2) as 別名 from 表
select concat (name,tel) as 用戶信息 from user
拼接:用戶姓名和聯繫方式,並將新拼接得到的字段起名爲“用戶信息”
as可以省略,即:
select concat (name,tel) 用戶信息 from user
- 執行算數計算
select 計算式 as 別名 from表
(“as 別名 ” 可以省略)
select id,price,quantity,price*quantity as 總價 from order
結果查詢:id 價格 數量 總價
select id,price,quantity,price*quantity from order
(“as 別名 ” 可以省略)