From: | Oliver Elphick <olly(at)lfix(dot)co(dot)uk> |
---|---|
To: | "Alan T(dot) Miller" <amiller(at)hollywood101(dot)com> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Something like 'to_days' in postgresql? Help with a |
Date: | 2003-12-11 10:07:14 |
Message-ID: | 1071137233.3439.705.camel@linda.lfix.co.uk |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On Thu, 2003-12-11 at 10:01, Oliver Elphick wrote:
> On Thu, 2003-12-11 at 08:44, Alan T. Miller wrote:
> > I am migrating an application over from mysql to postgresql and am a little
> > confused on how to write the following query in PostgreSQL. The date
> > functions and syntax is a world apart from MySQL and what I am used to. To
> > sum it up, I want to select a count of all records in a table that have been
> > added in the last 90 days. My current table has a field called 'created'
> > which is a timestamp. In MySQL the query goes as follows...
> >
> > SELECT COUNT(*) AS total
> > FROM orders
> > WHERE id = 'id'
> > AND TO_DAYS(NOW()) - TO_DAYS(created) <= 90
>
> CURRENT_DATE - created <= 90
Sorry, I forgot it was a timestamp column, not a date:
CURRENT_DATE - CAST(created AS date)
--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"The spirit of the Lord GOD is upon me; because the
LORD hath anointed me to preach good tidings unto the
meek; he hath sent me to bind up the brokenhearted, to
proclaim liberty to the captives, and the opening of
the prison to them that are bound."
Isaiah 61:1
From | Date | Subject | |
---|---|---|---|
Next Message | Sai Hertz And Control Systems | 2003-12-11 10:51:04 | Re: Something like 'to_days' in postgresql? Help with a MySQL |
Previous Message | Oliver Elphick | 2003-12-11 10:01:37 | Re: Something like 'to_days' in postgresql? Help with a |