Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Select do mês do anterior


luis Romao

Question

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 by Kakao
Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

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

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148876
    • Total Posts
      644882
×
×
  • Create New...