数据库
首页 > 数据库> > mysql小计合计

mysql小计合计

作者:互联网

语法 select * from 表名 group by ...with rollup

select
        ifnull(line, '总计') line,
        ifnull(vehicle, if(line!='总计','小计','合计')  ) vehicle,
        DATE_FORMAT(out_time,'%Y-%m-%d') as out_time,
        sum(minor_repair) minor_repair, sum(middle_repair) middle_repair,
        sum(face_lifting) face_lifting, sum(accident) accident,
        sum(total_amount) total_amount
        from report_out_depot
        where delete_flag = '0' and valid = '1' 
        group by line, vehicle
        with rollup

标签:repair,ifnull,sum,vehicle,小计,mysql,line,合计,out
来源: https://www.cnblogs.com/shi-yongcui/p/15753306.html