0

I try to select from my table and rollup to get the Total but i failed. Here is my table and values enter image description here

and the result i want like this

enter image description here

is this possible? my query :

select * from mytable group by id with rollup;

But my query failed to get the rollup values, please show me the way thanks

Mas Harjo
  • 73
  • 9

2 Answers2

3

try this:

select id,sum(qty),sum(import),sum(loss),sum(results) 
from mytable group by id asc with rollup;
Vijunav Vastivch
  • 4,153
  • 1
  • 16
  • 30
1

You can do something like below

    select coalesce(CAST(id as CHAR(50)),'Total'),
max(local),sum(import),sum(loss),sum(results)  from mytable group by id asc with rollup
Rams
  • 2,129
  • 1
  • 12
  • 19