Re: Something like 'to_days' in postgresql? Help with a MySQL
| От | Sai Hertz And Control Systems |
|---|---|
| Тема | Re: Something like 'to_days' in postgresql? Help with a MySQL |
| Дата | |
| Msg-id | 3FD84C18.9030503@sancharnet.in обсуждение исходный текст |
| Ответ на | Something like 'to_days' in postgresql? Help with a MySQL migration... ("Alan T. Miller" <amiller@hollywood101.com>) |
| Список | 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
В списке pgsql-novice по дате отправления: