how to implement group by grouping sets

Moderator: NorbertKrupa

Post Reply
sameer
Newbie
Newbie
Posts: 2
Joined: Thu Jan 31, 2013 5:32 am

how to implement group by grouping sets

Post by sameer » Fri Jan 24, 2014 6:29 am

Is there any way to implement group by grouping sets() like in oracle. I am writing queries that were previously implemented in oracle but I am not being able to find this feature in vertica. In oracle we can rewrite queries of the format

Code: Select all

SELECT a, b, SUM( c ) FROM t 
GROUP BY GROUPING SETS ( ( a, b ), ( a ), ( b ), ( ) );
to

Code: Select all

SELECT a, b, SUM( c ) FROM t 
  GROUP BY a, b 
UNION ALL
SELECT a, NULL, SUM( c ) FROM t 
  GROUP BY a 
UNION ALL
SELECT NULL, b, SUM( c ) FROM t 
  GROUP BY b 
UNION ALL
SELECT NULL, NULL, SUM( c ) FROM t;
Is there any way out to directly implement group by grouping sets in vertica avoiding multiple table scan...?? like in above example..please help

bwu@apptio.com
Newbie
Newbie
Posts: 2
Joined: Tue Nov 19, 2013 7:41 pm

Re: how to implement group by grouping sets

Post by bwu@apptio.com » Thu Feb 20, 2014 8:44 am

Not that I know of - but if you had to implement something like that and you are concerned with multiple table scans, one way to mitigate that is to do a group by on "a,b" first, put the result in a tmp table then the subsequent scans can be performed on that tmp table directly. If the cardinality game works out, you may save some time in the end,

Bing

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: how to implement group by grouping sets

Post by id10t » Thu Feb 20, 2014 1:40 pm

Hi!

[DELETED]
Last edited by id10t on Fri May 08, 2015 4:38 pm, edited 1 time in total.

NorbertKrupa
GURU
GURU
Posts: 527
Joined: Tue Oct 22, 2013 9:36 pm
Location: Chicago, IL
Contact:

Re: how to implement group by grouping sets

Post by NorbertKrupa » Thu Feb 20, 2014 2:01 pm

Please provide a sample data set, and the desired result. This will help us in identifying the best approach to your problem.
Checkout vertica.tips for more Vertica resources.

Post Reply

Return to “Vertica SQL”