如有以下数据

同一张表查询一个字段为空则取另一个字段

如果CANDATE不为空则取CANDATE否则取ENDDATE;

第一种:decode取法

  select a.code, decode(a.candate, null, a.enddate, a.candate) from ee a;
效果如下:

同一张表查询一个字段为空则取另一个字段

第二种:case when取法

select a.code, case
         when a.candate is null then
          a.enddate
         else
          a.candate
       end
  from ee a;

效果如下:

同一张表查询一个字段为空则取另一个字段

相关文章:

  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案