SQL将Null转化为0

使用ifnull()

select ifnull(sum(pay_price),0) as num from wm_order where pay_status=1 and pay_time between 1543766400 and 1543852800;

使用判断

public function  getGold($table,$querry,$start,$end,$status,$field)
    {
       $gold = Db::table($table)->where("$querry BETWEEN $start AND $end AND $status")->sum($field);
       if ($gold == null){
           $gold =0;
       }
       return $gold;
    }
原文地址:https://www.cnblogs.com/wangyang0210/p/10130932.html