Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 79729636A92 for ; Tue, 20 Apr 2010 13:11:56 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 94103-02-6 for ; Tue, 20 Apr 2010 16:11:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wy0-f174.google.com (mail-wy0-f174.google.com [74.125.82.174]) by mail.postgresql.org (Postfix) with ESMTP id 7E056636AEE for ; Tue, 20 Apr 2010 12:17:55 -0300 (ADT) Received: by wyb39 with SMTP id 39so3351853wyb.19 for ; Tue, 20 Apr 2010 08:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=2GytX/v39XxNNZFIdsJJtv6fme/yp9TTYA8kD59FAeg=; b=Mn5/qlZ8RdWWu29Z8UqZcy3OmxK6K9oAZF9JVeyIHqCUqnuTuTH1+dF1WfEWIn57Mu 8cruiRd5S+XqtVXvrMipUSDdCIPkYkgLz5FoIwnHmIckXZqNgFxFXeXl7sSTX0lKuv8+ on9oU9Ws/iS00l47LITiDv3AbbburJdWLuuek= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=S+Q92T4Dfn4EVEU1IH33SIFk4M24zUXy2s6cA96FgOJqvhihWdgYa9/nBGHVwGbmWI XIsZwa1/y5fZJDyst9WwZu80y/7BBzXu1NWxixUbnJWxi+dwIpvtAP/2Jmx0CinOriQC fvNFvJUo7JF81ry0RaAPf4+F1IP1nIQeI+KFw= MIME-Version: 1.0 Received: by 10.216.183.71 with HTTP; Tue, 20 Apr 2010 08:17:53 -0700 (PDT) In-Reply-To: <2A8BBCA2-814C-4E8D-BCE1-11FA2F8D120E@gmail.com> References: <2A8BBCA2-814C-4E8D-BCE1-11FA2F8D120E@gmail.com> Date: Tue, 20 Apr 2010 17:17:53 +0200 Received: by 10.216.175.142 with SMTP id z14mr4686947wel.73.1271776673453; Tue, 20 Apr 2010 08:17:53 -0700 (PDT) Message-ID: Subject: Re: How to max() make null as biggest value? From: Pavel Stehule To: Feixiong Li Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.03 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1.929 X-Spam-Level: X-Archive-Number: 201004/66 X-Sequence-Number: 33993 Hello 2010/4/14 Feixiong Li : > Hi , guys , > > I am newbie for sql, I have a problem when using max() function, I need g= et > null when there are null in the value list, or return the largest value a= s > usual, who can do this? > max() returns max value of some column create table foo(a int); insert into foo values(10); insert into foo values(33); postgres=3D# select * from foo; a ---- 10 33 (2 rows) Time: 0,524 ms postgres=3D# select max(a) from foo; max ----- 33 (1 row) there is function greatest postgres=3D# select greatest(1,2,34,2,1); greatest ---------- 34 (1 row) regards Pavel Stehule > i.e. =C2=A0max([1,2,3,4,5]) =3D> 5 > max([1,2,3,4,5,null]) =3D> 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 >