当前位置: 代码迷 >> PB >> 条件语句如何控制select的结果
  详细解决方案

条件语句如何控制select的结果

热度:91   发布时间:2016-04-29 09:54:41.0
条件语句怎么控制select的结果
比如说:
  我判断 a列 的值 大于 b列,select 则取 c 列
  否则, select 结果选 d 列

用pl/sql developer 怎么实现啊

------解决方案--------------------
select case sign(a - b) when 1 then c else d end from table
------解决方案--------------------
一楼正解。也可以这样:
select decode(sign(a - b), 1, c, d) from table;
大同小异
------解决方案--------------------
也可以
select case when a > b then c else d end from table
  相关解决方案