title: Calculate handling time per user based on timestamps and status changes
body: <p>I have one table.</p>
  <pre><code>user_id | status  | timestamp
  null    | null    | 2022-05-05 01:01:00
  null    | null    | 2022-05-05 01:02:00
  7461    | null    | 2022-05-05 01:03:00
  null    | open    | 2022-05-05 01:04:00
  null    | null    | 2022-05-05 01:06:00
  null    | on hold | 2022-05-05 01:09:00
  8474    | null    | 2022-05-05 01:10:00
  null    | null    | 2022-05-05 01:11:00
  null    | solved  | 2022-05-05 01:12:00
  2638    | null    | 2022-05-05 01:13:00
  null    | null    | 2022-05-05 01:16:00
  5721    | null    | 2022-05-05 01:17:00
  </code></pre>
  <p>I need to find the handling time for each user i.e. the time difference from when a user_id is assigned and the first status change. Also, if there is no status change until the next user is assigned, then I need to find the time difference from when the first user_id is assigned to when the next user_id is assigned.</p>
  <p>The output I'm looking for is</p>
  <pre><code>user_id | timestamp
  7461    | 00:01:00
  8474    | 00:02:00
  2638    | 00:04:00
  </code></pre>
  <p>I've been working on this for hours and I can't seem to get the right result. I know that a CTE would work but I don't know how to put in the conditions correctly. Any help would be appreciated.</p>
  <p>This is what I've tried and it works in MySQL. But I cannot use MySQL in this case.</p>
  <pre><code>   SELECT t1.user_id,
        MIN(SEC_TO_TIME(TIMESTAMPDIFF(SECOND, t1.timestamp, t2.timestamp))) AS timestamp
  FROM tab t1
  INNER JOIN tab t2
         ON t1.timestamp &lt; t2.timestamp
        AND t1.user_id IS NOT NULL
        AND t2.status IS NOT NULL 
  GROUP BY t1.user_id
  </code></pre>