条件"/>
MySQL count sum统计带条件
MySQL如何实现不一样的条件统计条数及总数
解决方法(laravel):
NematodeModel::groupBy('area_id')->where('area_id','>',1)->selectRaw('area_id,count(if(nematode_area > 0 and town_id>0, 1, null)) as nematode_township_num,sum(if(town_id=0, nematode_area, 0)) as nematode_area,count(if(dead_wood_area > 0 and town_id>0, 1, null)) as dead_wood_township_num,sum(if(town_id=0, dead_wood_area, 0)) as dead_wood_area,sum(if(town_id=0, preventive_task_total, 0)) as preventive_task_total,sum(if(town_id=0, preventive_task_complete, 0)) as preventive_task_complete')->get();
更多推荐
MySQL count sum统计带条件
发布评论