79500876

Date: 2025-03-11 13:16:56
Score: 0.5
Natty:
Report link

I answered a similar question for a PostgreSQL database.

I adapted it to your table names in a fiddle, it may need adaptations to run under Redshift (thus I don't post it as is here)
but it holds all the principles:

  1. identify sure starts of a span
  2. for each date, tell which subsequent date would be the next out of its 30-day span if it was itself a span start.
  3. then recurse over all potential span starts, marking the "surely valid" as valid then hoping to its successor indicated by step 2.
Reasons:
  • No code block (0.5):
Posted by: Guillaume Outters