Re: Something like 'to_days' in postgresql? Help with a MySQL

From: Sai Hertz And Control Systems <sank89(at)sancharnet(dot)in>
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 MySQL
Date: 2003-12-11 10:51:04
Message-ID: 3FD84C18.9030503@sancharnet.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Dear Alan T. Miller ,

>I am migrating an application over from mysql to postgresql and am a little
>confused on how to write the following query in PostgreSQL.
>
Migrating to PostgreSQL thats a wise mans act :-)

>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
>
>
Yes , it can be done this is how you will do it :
select
count(*) as total
from orders
where id = 'id ' <------- For a single id
AND ( age(current_timestamp,created) <= cast('90 days' as interval)) ;
------------------
For Multiple ids do:
-------------------
select
count(*) as total ,
orders.id as Order_No
from orders
where id = 'orders.id ' <------- For a multiple id
AND ( age(current_timestamp,created) <= cast('90 days' as interval))
group by orders.id;

Tell me if this works plz,

Regards,
V Kashyap

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Manu M P 2003-12-11 11:24:54 List Data bases and users
Previous Message Oliver Elphick 2003-12-11 10:07:14 Re: Something like 'to_days' in postgresql? Help with a