MySQL count sum统计带条件

编程入门 行业动态 更新时间:2024-10-25 16:27:45

MySQL count sum统计带<a href=https://www.elefans.com/category/jswz/34/1771358.html style=条件"/>

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统计带条件

本文发布于:2024-03-10 02:01:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1726725.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条件   MySQL   count   sum

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!