I have a table in ClickHouse with events of connecting and disconnecting to system.
Query select timestamp, username, event from table
gives following result.
timestamp | username | event |
---|---|---|
December 20, 2022, 18:24 | 1 | Connect |
December 20, 2022, 18:30 | 1 | Disconnect |
December 20, 2022, 18:34 | 1 | Connect |
December 21, 2022, 12:07 | 1 | Disconnect |
December 20, 2022, 12:15 | 2 | Connect |
December 20, 2022, 12:47 | 2 | Disconnect |
The session must be show in table as finished by the end of the day. If user was connected to system on 20th December and had no "Disconnect" after that in the same day, I have to add such 'Disconnect' event at the table with some query. And also I have to add row with event of 'Connect' to the table at 00:00 of next day. For example, in sample table you can see that user #1 had not finished session on 20th December, so I want to have the following result:
timestamp | username | event |
---|---|---|
December 20, 2022, 18:24 | 1 | Connect |
December 20, 2022, 18:30 | 1 | Disconnect |
December 20, 2022, 18:34 | 1 | Connect |
December 20, 2022, 23:59 | 1 | Disconnect |
December 21, 2022, 00:00 | 1 | Connect |
December 21, 2022, 12:07 | 1 | Disconnect |
December 20, 2022, 12:15 | 2 | Connect |
December 20, 2022, 12:47 | 2 | Disconnect |
Is there any way to amend the query so it will work as I described above? ClickHouse is not so common as Posrgres or SQL Server, as far as I know, so code in Postgres dialect will be fine, I will find out how to make the same with ClickHouse.