Re: How to max() make null as biggest value?

From: "Oliveiros" <oliveiros(dot)cristina(at)marktest(dot)pt>
To: "Feixiong Li" <feixiongli(at)gmail(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: How to max() make null as biggest value?
Date: 2010-04-20 15:30:49
Message-ID: 2B9CA716C0F54A07B23E624B5424D852@marktestcr.marktest.pt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)gmail(dot)com>
To: <pgsql-sql(at)postgresql(dot)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(at)gmail(dot)com
>
>
>
>
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Scott Marlowe 2010-04-20 16:04:51 Re: Problem with insert related to different schemas
Previous Message Pavel Stehule 2010-04-20 15:17:53 Re: How to max() make null as biggest value?