View Single Post

   
  #2 (permalink)  
Old 02-28-2008, 05:21 AM
Peter Lauri
 
Posts: n/a
Default RE: SUM() of 1 and NULL is 1 ?

IF(SUM(IF(Jan IS NULL, 0, Jan))>0, SUM(IF(Jan IS NULL, 0, Jan)), NULL)

This was just a guess



-----Original Message-----
From: C.R.Vegelin [mailto:cr.vegelin@hetnet.nl]
Sent: Wednesday, December 06, 2006 11:58 AM
To: mysql@lists.mysql.com
Subject: SUM() of 1 and NULL is 1 ?

Hi List,

I need to SUM() on months from a table like:
CREATE TABLE `data`
( `Jan` float default NULL,
....
) ENGINE=MyISAM; # V 5.0.15

Months may have NULL values, like:
INSERT INTO data (Jan) VALUES (1), (NULL);

However, when I use SELECT SUM(Jan) AS Jan,
the returned value is 1 in stead of NULL.
How to get a result NULL when in such a case ?

TIA, Cor

Reply With Quote