SQL query to retrieve all days of the previous month

Moderator: NorbertKrupa

Post Reply
bhaggyit
Newbie
Newbie
Posts: 10
Joined: Thu Apr 04, 2013 10:48 am

SQL query to retrieve all days of the previous month

Post by bhaggyit » Wed Sep 03, 2014 11:46 am

Guys,
Could someone help me with SQL query to retrieve all days of the previous month?

Regards,
Bugs.

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: SQL query to retrieve all days of the previous month

Post by JimKnicely » Wed Sep 03, 2014 12:35 pm

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

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “Vertica SQL”