Imagine we have the following table where 0 is a start time, and 1 is an end time of the same kind x process.
| way | time | kind |
|---|---|---|
| 0 | 12:12.34 | x |
| 1 | 12:12.55 | x |
| 0 | 12:15.22 | x |
| 1 | 12:15.59 | x |
| 0 | 12:16.07 | x |
| 1 | 12:16.42 | x |
I would like get as result:
| kind | start | end | next_start |
|---|---|---|---|
| x | 12:12.34 | 12:12.55 | 12:15.22 |
| x | 12:15.22 | 12:15.59 | 12:16.07 |
| x | 12:16.07 | 12:16.42 | (so on) |
In time order the first three events should be pone in start, end, next start column because following the way 0 = start, 1= end, and so on.
i did in this way but there is an error regarding next_start
SELECT kind, start, end, next_start
FROM(
SELECT kind, F.time as start, S.time as end, max(F.time) as next_start
from Table F
INNER JOIN Table S
ON F.kind = S.kind
WHERE end>start
AND next_start> end
GROUP BY kind, start, end
)
order by next_start