MySQL Forums
Forum List  »  Newbie

Re: MySQL Rollup - All possible column super aggregations
Posted by: Rathi Rao
Date: June 02, 2017 02:24AM

Hi Peter,

Yes I have tried that. Please have a look at this query.

I inserted two more rows to the table in addition to the rows I had mentioned in my previous mail

insert into testrollup values (100,10,145,'abc',90);
insert into testrollup values (100,10,123,'abc',85);

Now, problem statement - With all the other aggregations, I want to get the sum(itemtypeid,districtid) for district = 'abc' and unitid = 10 which would be 150

The query goes like this

select
itemtypeid,unitid,dealerid,districtid,concat(itemtypeid,'-',districtid)itemdistrict,
sum(num)
from testrollup
where districtid = 'abc' and unitid =10
group by itemtypeid,unitid,dealerid,districtid,concat(itemtypeid,'-',districtid) with rollup;


I do get the rows which have the sum as 150. But the row looks like this

100,10,NULL,NULL,NULL,150
100,NULL,NULL,NULL,NULL,150

I do not get to see the row as NULL,NULL,NULL,NULL,100-abc,150

I observe that NULLs happen to start from right and proceeds to left. Is such a super aggregate row achievable or must the UNION approach be taken?NEF

Thanks
Rathi

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.