From: Oliver Elphick <olly@lfix.co.uk>
To: gdaswani@odc.net
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] HAVING confusion..
Date: Mon, 22 Feb 1999 07:07:58 +0000
Message-ID: <199902220707.HAA20343@linda.lfix.co.uk> (raw)
In-Reply-To: <gdaswani@Vorlon.odc.net> <Pine.LNX.4.04.9902211428480.16742-100000@Vorlon.odc.net>
"George Henry C. Daswani" wrote:
>Hello,
>
> I'm using postgresql 6.4.2 and i'm having a problem with the
>"HAVING" clause..
>
>
>Basically I do
>
>SELECT u_id,expire_date FROM users HAVING expire_date >= (NOW())
...
>and it keeps failing with
>ERROR: This is not a valid having query!
You should only use HAVING with GROUP BY; for what you are doing, you
just want WHERE.
SELECT u_id,expire_date FROM users
WHERE expire_date >= date(now());
u_id |expire_date
-----+-----------
fred | 21-03-1999
tom | 01-05-1999
harry| 01-05-1999
sarah| 21-03-1999
dick | 12-04-1999
(5 rows)
SELECT expire_date,COUNT(*) FROM users
GROUP BY expire_date
HAVING expire_date >= date(now());
expire_date|count
-----------+-----
21-03-1999| 2
12-04-1999| 1
01-05-1999| 2
(3 rows)
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP key from public servers; key ID 32B8FAA1
========================================
"The LORD bless thee, and keep thee; The LORD make his
face shine upon thee, and be gracious unto thee; The
LORD lift up his countenance upon thee, and give thee
peace." Numbers 6:24-26
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: olly@lfix.co.uk, gdaswani@odc.net
Subject: Re: [SQL] HAVING confusion..
In-Reply-To: <199902220707.HAA20343@linda.lfix.co.uk>
References: <199902220707.HAA20343@linda.lfix.co.uk>
* 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