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 > are the aggregated columns taken as null?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-02-07, 16:48
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
 
Join Date: Jan 2005
Posts: 75
are the aggregated columns taken as null?

Hi ,

Are the aggregated columns taken as null in DB2. like if i define sum(col1) will this be considered as null or not null column (if the column is defined as not null)

Thanks,
Waseem
Reply With Quote
  #2 (permalink)  
Old 06-03-07, 04:04
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
sum(col1) is considered nullable even if col1 is NOT NULL.

( if the resultset is empty, sum(col1) will be NULL )
Reply With Quote
  #3 (permalink)  
Old 01-07-09, 18:49
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
 
Join Date: Jan 2005
Posts: 75
and what would be the result if the aggregating column something like this sum(10 + null) as column1?
Reply With Quote
  #4 (permalink)  
Old 01-08-09, 09:57
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by ahmedwaseem2000
and what would be the result if the aggregating column something like this sum(10 + null) as column1?
Also NULL: SUM(expr) only includes rows for which the expression is not NULL. If there is at least one such row, the result is not NULL, otherwise it is.

With AVG(expr) it's even more apparent: the denominator will be the number of rows for which expr is not NULL.
Actually, the same holds for any of the other aggregate functions:
COUNT(expr) only counts the number of not NULL expr's.
In that respect, COUNT(*) is actually equivalent to COUNT(1).
MIN(expr) and MAX(expr) equally ignore NULL expressions.
All (except for COUNT(expr) of course) return NULL when applied on an empty set, i.e., either an empty table (after having applied the WHERE condition), or an empty list (after removal of the NULL expressions).
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
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