1
First of all, good morning guys, I would like a little help in filtering out every day of the current month, where I could get from the first to the 30th or 31st of the current month, where I wouldn’t define what month I want but what’s in the machine.
How could I do a search without a fixed month?
base_cliente_comprou (ID) AS (
SELECT * FROM tb_pedido
INNER JOIN base ON cliente = ped_cli_id
WHERE ped_data BETWEEN '2020-07-01 00:00:00' AND '2020-07-31 23:59:59' AND ped_cli_id NOT IN (cliente)
)
Thanks in advance.
only the month, or month and year?
– Claudio Lopes
For example:
ped_data >= date_trunc('month', CURRENT_DATE) AND ped_data < (date_trunc('month', CURRENT_DATE) + interval '1 month')
– anonimo
Hello guys, thank you so much for the answer, I tested the two ways you sent me and it worked super well, thank you, I’m already applying in my code. Hug...
– joaovictor-bs
Claudio Lopes, I needed the year and I forgot to ask too, but Marcos' answer downstairs ends up getting the year too, well thank you very much anyway ;)
– joaovictor-bs
Just for the current month can simplify to:
data_trunc('month', CURRENT_DATE) = date_trunc('month', ped_data)
– anonimo