IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Inconsitent grouping when using Sum, Case, Group by in DB2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Sravs

New User


Joined: 20 Jul 2009
Posts: 1
Location: Hyderabad

PostPosted: Wed Jun 08, 2011 8:15 pm
Reply with quote

Hi,

I am trying to execute the below cursor and getting the error message 'Inconsistent Grouping'.

Code:
SELECT COL1, B.COL2,
         SUM(CASE COL5 WHEN 'AAAAA' THEN 1               
                                  ELSE 0 END ) AS COVG,
         CASE COL5 WHEN 'AAAAA' THEN COL6
                           ELSE ' ' AS FORM
FROM  TABLE1 A,
          TABLE2 B
WHERE A.COL1 = B.COL1
GROUP BY COL1, B.COL2
WITH UR
;

I want to display the value of COL6 when value in the COL5 is equal to 'AAAAA' for a particular row fetched from TABLE2.

Please help me.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Jun 08, 2011 9:26 pm
Reply with quote

well that's exactly what it is.
btw, you missed an END when copying.

Code:
SELECT COL1, B.COL2,
         SUM(CASE COL5 WHEN 'AAAAA' THEN 1               
                                  ELSE 0 END ) AS COVG,
         CASE COL5 WHEN 'AAAAA' THEN COL6
                           ELSE ' ' END AS FORM
FROM  TABLE1 A,
          TABLE2 B
WHERE A.COL1 = B.COL1
GROUP BY COL1, B.COL2 ,CASE COL5 WHEN 'AAAAA' THEN COL6 ELSE ' ' END
WITH UR

will give you another result. but then the sum COVG probably isn't what you want
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Grouping by multiple headers DFSORT/ICETOOL 7
No new posts Compare latest 2 rows of a table usin... DB2 1
No new posts Zunit Test case editor error Testing & Performance 4
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
Search our Forums:

Back to Top