MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DB2- Null value in GROUP BY Clause

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
rajeeva
Beginner


Joined: 14 Apr 2005
Posts: 1
Topics: 1

PostPosted: Mon Apr 18, 2005 2:57 am    Post subject: DB2- Null value in GROUP BY Clause Reply with quote

Hi,
I have the clarification regarding how the null values need to be appear after using Group by clause.
Example: Below shows the table containing the values
Code:

DeptNumber         DivisionCode              SalesAmt
---------------   -------------------     -----------------
D1                  DIV1                        100
D1                  DIV1                        120
D1                  DIV1                       NULL
D2                  DIV2                        100
D2                  DIV2                       NULL
D2                  DIV2                         20
D3                  DIV3                        100
D3                  DIV3                        300
--------------------------------------------------------

What will be result after using GROUP BY clause ?

Code:

SELECT DEPTNUMBER
      ,DIVISIONCODE
      ,AVG(SALESAMT)
  FROM DEPTTABLE
 GROUP BY DEPTNUMBER
         ,DIVISIONCODE


Please give the result after above SQL statement is executed.

Thanks and regards,
Rajeeva
Back to top
View user's profile Send private message
s_shivaraj
Beginner


Joined: 21 Sep 2004
Posts: 140
Topics: 14
Location: Chennai, India

PostPosted: Mon Apr 18, 2005 3:27 am    Post subject: Reply with quote

Rajeeva,
Please don't post your question under an unrelated Topic.

Here is the answer to your question.
NULL values wouldn't be taken into consideration when calculating the Average. That row will be ignored when calculating the average.

So the result will be like

Code:

DeptNumber       DivisionCode        SalesAmt
--------------- ------------------- -----------------
D1                DIV1                 110
D2                DIV2                  60
D3                DIV3                 200

_________________
Cheers
Sivaraj S

'Technical Skill is the Master of complexity, while Creativity is the Master of Simplicity'
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group