Guys,
Could someone help me with SQL query to retrieve all days of the previous month?
Regards,
Bugs.
SQL query to retrieve all days of the previous month
Moderator: NorbertKrupa
- JimKnicely
- Site Admin
- Posts: 1825
- Joined: Sat Jan 21, 2012 4:58 am
- Contact:
Re: SQL query to retrieve all days of the previous month
Here is one solution:
Code: Select all
SELECT the_date
FROM (SELECT ADD_MONTHS(DATE_TRUNC('MONTH', SYSDATE), -1) + (ROW_NUMBER() OVER () - 1) the_date
FROM tables) foo
WHERE the_date < DATE_TRUNC('MONTH', SYSDATE);
Jim Knicely
Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.
Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.