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;
    }

 

posted @ 2018-12-17 13:15  。思索  阅读(6207)  评论(0编辑  收藏  举报