1連接列值
使用concat函數連接來自多個列的數值. 在DB2, Oracle和PostgreSQL中,"||"是concat函數的簡寫方式,"+"是SQL Server中的簡寫方式.
select
name||' is a '||type as msg from animal where ...
select
name+' is a '+type as msg from animal where...
select
concat(name, ' is a ', type) as msg from animal where ...
2.在SELECT語句中使用條件邏輯
case表達式可以針對查詢的返回值執行條件邏輯. 可以給case表達式取別名, 使結果集更易讀. else子句是可選的, 如果沒有使用else, 對于不滿足判斷條件的行, case表達式會返回NULL.
select ename, sal,
case when sal<=2000 then 'UNDERPAID'
case when sal>=4000 then 'OVERPAID'
else 'OK'
end as status
from emp
posted on 2008-07-14 21:16
周銳 閱讀(1552)
評論(0) 編輯 收藏 所屬分類:
MySQL 、
Oracle 、
SQL Server