luis Romao 0 Posted February 24, 2015 Report Share Posted February 24, 2015 (edited) Olá pessoa, Preciso da ajuda para consultar os registros do mês anterior sem a necessidade de informar datas Em Mysql eu consigo fazer.where ( (month(`arte`.`artedataregistro`) = month(curdate())-1) and (year(`arte`.`artedataregistro`) = year(curdate())) ) Como fazer em Postgres? Edited February 24, 2015 by Kakao Quote Link to post Share on other sites
0 Kakao 0 Posted February 24, 2015 Report Share Posted February 24, 2015 (edited) where date_trunc('month', arte.artedataregistro) = date_trunc('month', current_date - interval '1 month') Edited February 24, 2015 by Kakao Quote Link to post Share on other sites
0 Dr. House 0 Posted February 24, 2015 Report Share Posted February 24, 2015 where extract(month from data) = X and extract(year from data) = xxxx Quote Link to post Share on other sites
0 luis Romao 0 Posted February 24, 2015 Author Report Share Posted February 24, 2015 Deu certo, muito obrigado!! Quote Link to post Share on other sites
0 Dr. House 0 Posted February 24, 2015 Report Share Posted February 24, 2015 qual dos 2? Quote Link to post Share on other sites
0 luis Romao 0 Posted February 24, 2015 Author Report Share Posted February 24, 2015 wheredate_trunc('month', arte.artedataregistro) =date_trunc('month', current_date - interval '1 month') Quote Link to post Share on other sites
0 Maycon Noetzold 0 Posted July 3, 2019 Report Share Posted July 3, 2019 WITH INTERVALO_30 AS( SELECT CAST(EXTRACT(YEAR FROM CURRENT_DATE-30)||'-'||EXTRACT(MONTH FROM CURRENT_DATE-30)||'-01' AS DATE) AS DATA_INI, (DATE_TRUNC('MONTH', CURRENT_DATE-30) + INTERVAL '1 MONTH - 1 DAY')::DATE AS DATA_FIM ) SELECT DATA_INI, DATA_FIM FROM INTERVALO_30 Quote Link to post Share on other sites
Question
luis Romao 0
Olá pessoa,
Preciso da ajuda para consultar os registros do mês anterior sem a necessidade de informar datas
Em Mysql eu consigo fazer.
Como fazer em Postgres? Edited by KakaoLink to post
Share on other sites
6 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.