Howdy, Feixiong.
I dunno if this results out of the box, but try something like this
SELECT CASE WHEN (COUNT(*) <> COUNT("YourColumnName")) THEN NULL ELSE
MAX("YourColumnName") END AS "...."
FROM t_your_table;
I don't have an example table to test so this is "air code", but if you use
count on a column with nulls the return value is different from count(*)
HTH
Best,
Oliveiros Cristina
----- Original Message -----
From: "Feixiong Li" <feixiongli@gmail.com>
To: <pgsql-sql@postgresql.org>
Sent: Wednesday, April 14, 2010 5:33 AM
Subject: [SQL] How to max() make null as biggest value?
> Hi , guys ,
>
> I am newbie for sql, I have a problem when using max() function, I need
> get null when there are null in the value list, or return the largest
> value as usual, who can do this?
>
> i.e. max([1,2,3,4,5]) => 5
> max([1,2,3,4,5,null]) => null
>
> thanks in advance!
>
> Feixiong
> feixiongli@gmail.com
>
>
>
>
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql