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 > simple query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-04, 07:31
dr_suresh20 dr_suresh20 is offline
Registered User
 
Join Date: Sep 2003
Posts: 218
simple query

Hi,

I am using db2 ese v8.1.4a on win2k platform and I have the following question:

My select query looks some thing like this...

SELECT SUM(A.Col1 + B.Col1), SUM(A.Col1 - Col1)
FROM TableA A, TableB B
WHERE A.ID = B.ID

Now the issue is, that how to exclude NULL values from the tables so that they don't appear in resultant.

Any help is appreciated.

Thanks,
Reply With Quote
  #2 (permalink)  
Old 07-23-04, 08:13
AStefan AStefan is offline
Registered User
 
Join Date: Jun 2004
Posts: 57
Is It Ok?

If I understand corectly, I think you can use something like that

SELECT * FROM
(
SELECT A.id, SUM(A.a + B.b) as FIRST_, SUM(A.a - B.b) AS SECOND_
FROM A, B
WHERE A.id = B.id
GROUP BY A.id
) AS RESULT
WHERE RESULT.FIRST_ IS NOT NULL AND RESULT.SECOND_ IS NOT NULL
Reply With Quote
  #3 (permalink)  
Old 07-23-04, 08:49
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
SELECT SUM(A.Col1 + B.Col1), SUM(A.Col1 - B.Col1)
FROM TableA A, TableB B
WHERE A.ID = B.ID
AND A.Col1 IS NOT NULL
AND B.Col1 IS NOT NULL
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 08-13-04, 15:01
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
Do you want nulls treated as zeroes? (1 + null = 1) or do you want the rows with nulls completely ignored? (1 + null is excluded)

If you want to include the rows with nulls in the calculations, then use the COALESE or VALUES function to convert nulls to zero.
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