Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Presto sql to get last months data till current day data?

Tags:

date

sql

presto

How to get last month's data using presto sql

tried this :

SELECT *
FROM tabl
where my_date > cast(current_date - interval '1' month as timestamp)

But this will include current months and exclude some previous months days

How to get only last months data and current month data included like this

last month data + data until today


1 Answers

Use date_trunc():

where my_date < date_trunc('month', current_date) and
      my_date >= date_trunc('month', current_date) - interval '1' month

If you want everything since the first day of the previous month:

where my_date >= date_trunc('month', current_date) - interval '1' month
like image 151
Gordon Linoff Avatar answered Oct 23 '25 07:10

Gordon Linoff