title: Set sequential number on entries with specific condition
body: <h2>Situation</h2>
  <p>I'm preparing the migration of user data and I have a list of user subscriptions, for which I try to give every user a member id.</p>
  <p>We only want to migrate active subscriptions, which are identified with the value 1 in the row &quot;active&quot;.  The oldest user should get the lowest number and count upwards from there.</p>
  <h2>Problem</h2>
  <p>The oldest users already have renewed their subscription. Please have a look at this image:</p>
  <p><a href="https://i.stack.imgur.com/LCZtq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LCZtq.png" alt="" /></a></p>
  <p>If I order the dataset by date and set a sequential number from there, the oldest user doesn't get the lowest number since we only migrate active subscriptions. In the above image, the oldest user &quot;one&quot; should have the id 1 but gets the id 5 under my current setting.</p>
  <h2>Possible Solution</h2>
  <p>I'm struggling to find a solution to solve this problem. I was thinking about finding a way to write:</p>
  <ul>
  <li>a) sort by date and set an ongoing member id</li>
  <li>b) check for each user mail adress with active = 1, if there is already an entry existing with active = 0 and if yes, overwrite the member id.</li>
  </ul>
  <p>afterwards, it should look like this:</p>
  <p><a href="https://i.stack.imgur.com/djLon.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/djLon.png" alt="" /></a></p>