SQL: Get Latest Day for each month in a dataset

Steve Sohcot
Oct 17, 2022

--

For a list of dates, I needed to get the latest date in each month. The results are not necessarily the last day of the month.

The data looked like this, where the highlighted values are what I wanted returned:

The trick was to parse out the pieces of the date (year, month, day), then get the latest day, while grouping by the month/year:

The final output gave these results:

--

--

No responses yet