Mas Harjo
Mas Harjo

Reputation: 73

mysql select * from table group by id with rollup

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

Upvotes: 0

Views: 470

Answers (2)

Rams
Rams

Reputation: 2159

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

Upvotes: 1

Vijunav Vastivch
Vijunav Vastivch

Reputation: 4211

try this:

select id,sum(qty),sum(import),sum(loss),sum(results) 
from mytable group by id asc with rollup;

Upvotes: 3

Related Questions