I'm new to SQL and I'm breaking my head to put together a query that returns the results I want.
I have a field whose date format is as follows: 2018-12-13T18:01:16.573-02:00
.
I have a $Período
variable whose values are (month / year): 12/2017
, 01/2018
, 02/2018
, etc.
This query worked:
SELECT *
FROM nomedatabela
WHERE TO_CHAR(colunadata, 'MM/YYYY') = ($PERIODO)
However, the period I want to query when selecting the variable is as follows:
- When you select the variable whose value is
02/2018
, the query looks for the records of06/01/2018
to05/02/2018
; - When you select the variable whose value is
03/2018
, the query looks for the records of06/02/2018
to05/03/2018
; - and so on.
How can I do this?