pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliveiros <oliveiros.cristina@marktest.pt>
To: Feixiong Li <feixiongli@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: How to max() make  null as biggest value?
Date: Tue, 20 Apr 2010 16:30:49 +0100
Message-ID: <2B9CA716C0F54A07B23E624B5424D852@marktestcr.marktest.pt> (raw)
References: <2A8BBCA2-814C-4E8D-BCE1-11FA2F8D120E@gmail.com>

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 




view thread (6+ messages)  latest in thread

Message-ID: <2B9CA716C0F54A07B23E624B5424D852@marktestcr.marktest.pt>
Permalink:  ../2B9CA716C0F54A07B23E624B5424D852@marktestcr.marktest.pt/
Also on:    postgresql.org/message-id/2B9CA716C0F54A07B23E624B5424D852@marktestcr.marktest.pt

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: oliveiros.cristina@marktest.pt, feixiongli@gmail.com
  Subject: Re: How to max() make  null as biggest value?
  In-Reply-To: <2B9CA716C0F54A07B23E624B5424D852@marktestcr.marktest.pt>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox