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