tp5連式操作查詢數據,根據條件sum if求和

$result = Db::name('server_bill')
    ->where(['user_id'=>$userId,'status'=>1])
    ->field(["sum(if(type in (1,2),money,0)) as income","sum(if(type=3,money,0)) as expend"])
    ->find();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章