I have a table with user statuses changes like this:
| User | New state | Start Time | End Time |
|---|---|---|---|
| joe | st0 | 08:00:00 | 08:01:00 |
| joe | st1 | 08:01:00 | 09:00:00 |
| alice | st1 | 08:30:00 | 09:01:00 |
| joe | stX | 09:00:00 | 11:00:00 |
| alice | st2 | 09:01:00 | 11:50:00 |
| joe | st3 | 11:20:00 | 14:50:00 |
| joe | stx | 14:50:00 | 18:50:00 |
Where stx is an offline state. Id like to derive a table which will show me the segments of login-logout for each user. After transforming the above, the result should be:
| User | Start Time | End Time |
|---|---|---|
| joe | 08:00:00 | 11:00:00 |
| alice | 08:30:00 | now() |
| joe | 11:20:00 | 18:50:00 |
Any guide about how I could achieve that?
Using PostgreSQL 8.0.2