All Forums Database
ksaikrishna 26 posts Joined 08/11
26 Jun 2012
Can we use GROUPING ,GROUPING_ID,Grouping Sets

Can some one help me how to use GROUPING ,GROUPING_ID,Grouping Sets in terdata?

mjasrotia 66 posts Joined 08/11
27 Jun 2012

Krishna,

 

You can go through the below chapter to clear your thoughts about GROUPING SETS:

==>SQL Reference Data Manipulation Statements

====>Chapter: The SELECT Statement

========>GROUPING SETS OPTION

In essence its a way to aggregate data for different groups within the same query.

e.g SELECT DIST_ID , STORE_ID , PROD_ID , SUM(SALES_AMT) FROM SALES_TBL GROUP BY GROUPING SETS ((DIST_ID) , (DIST_ID , STORE_ID) , (DIST_ID m STORE_ID , PROD_ID))

The above case could also be handled using a ROLLUP( GROUP BY ROLLUP(DIST_ID , STORE_ID , PROD_ID)

In a way its UNION of data aggregated on different groups.

 

ksaikrishna 26 posts Joined 08/11
27 Jun 2012

Thanks mjasrotia

You must sign in to leave a comment.