Hy, i want to split the time to 2 columns by Event type.
My Table looks like this:
| User | EventType | Time |
|---|---|---|
| name1 | Logon | 14.08.2022 23:51:12 |
| name2 | Logoff | 12.08.2022 09:12:44 |
| name2 | Logon | 11.08.2022 23:51:01 |
| name1 | Logoff | 16.08.2022 08:27:55 |
And i want to split the Time with EventType like this in SQLite:
| User | Logon | Logoff |
|---|---|---|
| name1 | 14.08.2022 23:51:12 | 16.08.2022 08:27:55 |
| name2 | 11.08.2022 23:51:01 | 12.08.2022 09:12:44 |
any ideas?
>Solution :
assuming there is no double logons without logoff, as in your example, you can do this:
select user,
logon_time,
logoff_time
from (select user,
time logon_time,
lead(time) over(partition by user order by time) logoff_time,
event_type
from test_table)
where event_type = 'Logon';
The LEAD function takes value from next line using ordering from "order by" part. In your case a logoff event takes place only after a logon, so it might working