您好,我对汇总 mysql 查询有疑问。我想得到每列的总数。我使用 mysql SUM() 和 ROLLUP 来获得结果。但是在添加的新行上,它会复制最后一行的数据。我怎样才能删除这些数据。我提供了一张关于我真正需要实现的目标的图片。
这是我的查询。
SELECT IFNULL(payments.id, "General Total"), payments.driver_id, payments.vehicle_specifications_id,payments.admins_id, payments.vehicle_id, payments.boundaries, payments.cashbond_payments, payments.loans, payments.penalties, SUM(payments.total_payments), a.first_name, a.mid_name, a.last_name, d2.date, d.first_name, d.mid_name, d.last_name, v.plate_number, v2.car_rate FROM payments INNER JOIN admins AS a ON payments.admins_id = a.id INNER JOIN drivers AS d ON payments.driver_id = d.id INNER JOIN dispatch AS d2 ON payments.dispatch_id =d2.id INNER JOIN vehicles AS v ON payments.vehicle_id = v.id INNER JOIN vehicle_specifications AS v2 ON payments.vehicle_specifications_id = v2.id GROUP BY payments.id WITH ROLLUP