posts - 431,  comments - 344,  trackbacks - 0
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 周锐 阅读(1530) 评论(0)  编辑  收藏 所属分类: MySQLOracleSQL Server

只有注册用户登录后才能发表评论。


网站导航: