-1

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

Mas Harjo
  • 73
  • 9
  • 1
    I think you could illustrate the problem with fewer rows and/or an sqlfiddle/rextest. – Strawberry May 10 '17 at 10:07
  • You SELECT id, class, defaut, and input, but only group by two of those columns. While there is a functional dependancy in place, for the purposes of ROLLUP, this doesn't quite make sense. – Strawberry May 10 '17 at 10:17

2 Answers2

2

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
Shadow
  • 33,525
  • 10
  • 51
  • 64
0

Final Query :

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

enter image description here

Thank for your helps.

Mas Harjo
  • 73
  • 9