title: I need to get datediff on each row based on previous row
body: <p>I have table:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Rownr</th>
  <th>ID</th>
  <th>SalesDate</th>
  <th>result</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>1</td>
  <td>2021-01-05</td>
  <td>NULL</td>
  </tr>
  <tr>
  <td>2</td>
  <td>1</td>
  <td>2021-02-05</td>
  <td>NULL</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2</td>
  <td>2021-02-03</td>
  <td>NULL</td>
  </tr>
  <tr>
  <td>4</td>
  <td>2</td>
  <td>2021-03-04</td>
  <td>NULL</td>
  </tr>
  <tr>
  <td>5</td>
  <td>3</td>
  <td>2021-05-04</td>
  <td>NULL</td>
  </tr>
  <tr>
  <td>6</td>
  <td>4</td>
  <td>2021-07-03</td>
  <td>NULL</td>
  </tr>
  <tr>
  <td>7</td>
  <td>4</td>
  <td>2021-09-05</td>
  <td>NULL</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I have to insert into result value either 1 or 0 depending on date difference of previous row date.
  1 indicates new client and 0 indicates old client.</p>
  <p>For example:</p>
  <p>For rownr 1 i need to look date of rownr 2 and make sure it has same ID and if datediff is for example 1month then insert 1 else insert 0.
  For row nr2 as there is no previous record with this ID it gets value 1
  On this sample table rownr5 id3 gets value 1 as it has no previous records.</p>
  <p>And so on. This table gets new rows every day and needs this 1 or 0 into every row.</p>
  <p>Goal is to indicate if customer is new or old. If customer has no previous orders it gets value 1 as a new customer. If customer has previous orders but datediff is long then it gets value 1 and indicates a old customer that came back. If customer has previous orders and datediff is short then it gets value 0 and indicates a regular customer.</p>
  <p>How should i approach this problem? Any direction to solving this problem is appreciated.</p>