If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > thougt ilshi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-11, 04:50
thar thar is offline
Registered User
 
Join Date: Feb 2011
Posts: 3
thougt ilshi

Hi All
Can multiple group by clause be used in single query. The requirement is to have a group by on three combinations . I have a table with composite keys
Say A,B,C ,
The group by's have to done on
1] A,B
2] A,C
3] A

Can it be done using single query, or three different queries have to be done for three combinations.
Please advice
Reply With Quote
  #2 (permalink)  
Old 02-24-11, 05:13
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
possibly "group by grouping sets ... "
Reply With Quote
  #3 (permalink)  
Old 02-24-11, 06:29
thar thar is offline
Registered User
 
Join Date: Feb 2011
Posts: 3
entribi Consulting

Thanks for the reply

i tried this query but it results in error

SELECT ER_NBR, INSTR_ID, sum( STRT_INSTR_PRICE ) AS pris
FROM MATB252
GROUP BY GROUPING
SETS(( ER_NBR ))


DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: SETS;UNION

Any idea .
Reply With Quote
  #4 (permalink)  
Old 02-24-11, 10:03
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
are you on mainfraame? of luw?

what db2 version are you on?
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #5 (permalink)  
Old 02-24-11, 11:43
thar thar is offline
Registered User
 
Join Date: Feb 2011
Posts: 3
Its Unix ,DB2 7.2
Reply With Quote
  #6 (permalink)  
Old 02-24-11, 20:37
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Code:
SELECT ER_NBR, INSTR_ID, sum( STRT_INSTR_PRICE ) AS pris
FROM MATB252
GROUP BY GROUPING
SETS(( ER_NBR ))
In this example, try including instr_id in the grouping sets.
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On