title: DB2 How to convert the following "with temp as" into a normal select statement
body: <p>I'm trying to do an insert with this "with" statement but it seems like it supports select statement only, therefore I want to convert it into select statement. I'm just amazed on how this is working. Got a similar example on stack and changed it to fit my needs.</p>
  
  <pre><code>with temp (startdate, enddate, maxdate) as (
      select min(salesdate) startdate, min(salesdate)+3 months enddate, max(salesdate) maxdate
      from SALES
      union all
      select startdate + 3 months + 1 days, enddate + 3 months + 1 days, maxdate from temp 
      where enddate &lt;= maxdate
  )
  select startdate, min(enddate, maxdate) from temp;
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Edit</strong>: It seems my query is misunderstood. Here is the pseudo code of what the query is supposed to be doing. The query is returning the expected result which is pretty amazing to me. I don't know how the recursive doesn't overlap after I added 1 day. After writing the pseudo code, I see that the <code>select startdate + 3 months + 1 days</code> should have been written as <code>select enddate + 1 days</code> which logically says what it's supposed to do instead of magically work:</p>
  
  <pre><code>rows = []
  startdate = min(salesdate)
  enddate = startdate + 3 months
  maxdate = max(salesdate)
  i = 0;
  do {
      rows[i++] = [startdate, min(enddate, maxdate)] // min for final iteration where enddate &gt; maxdate.
      startdate = enddate + 1 days
      enddate = enddate + 1 days + 3 months // aka: startdate + 3 months
  } while (enddate &lt;= maxdate)
  return rows
  </code></pre>
  
  <p>Hence, I've broken a huge date range into smaller chunks of 3 months ranges. Whether it is exactly 90 days or 91 days is not important, as long as I get every single date without gap and without overlap.</p>