Mas Harjo Mas Harjo - 5 months ago 25
MySQL Question

mysql sum(column2 - column1) with rollup

i need some help with my mysql query . I have one table that look like :

enter image description here

And then i want to select with this query :

select id, class, defaut, input, round(input - defaut) test from table1
group by class, id with rollup


I want the output like :

enter image description here

But my query given me like that :

enter image description here

please for your help, thanks

Answer Source

You need to sum the default, input and the calculated fields to get the expected output, otherwise rollup will simply return the value from the last record:

select id, class, sum(defaut), sum(input), sum(round(input - defaut)) test from table1
group by class, id with rollup