hcwzwx 发表于 2018-10-11 08:15:03

MySQL中关于coalesce的用法

  coalesce在sql中其实是一个很有用的函数;coalesce()主要作用是返回第一个非null值;
  例如:
  coalesce(null, null, 2, 4) ==> 返回2,
  coalesce(null,null) ==> 返回null
  当然,coalesce()函数的最主要作用判断一个值是不是null,如果是,则返回一个定值,
  例如:
  coalesce(money,0)==> 解释: 返回数据库中字段为money的值,如果money为null,则返回0;
  这个就相当于case when ... then ... end

页: [1]
查看完整版本: MySQL中关于coalesce的用法