With 5+ years of experience as a Data Engineer and having taken 100+ interviews, I’ll share not just the solution, but also the thinking process interviewers expect.
DDL and insert query:
CREATE TABLE server_utilization (
server_id INT,
status_time DATETIME,
session_status VARCHAR(10)
);
INSERT INTO server_utilization (server_id, session_status, status_time) VALUES
(1, 'start', '2022-08-02 10:00:00'),
(1, 'stop', '2022-08-04 10:00:00'),
(1, 'stop', '2022-08-13 19:00:00'),
(1, 'start', '2022-08-13 10:00:00'),
(3, 'stop', '2022-08-19 10:00:00'),
(3, 'start', '2022-08-18 10:00:00'),
(5, 'stop', '2022-08-19 10:00:00'),
(4, 'stop', '2022-08-19 14:00:00'),
(4, 'start', '2022-08-16 10:00:00'),
(3, 'stop', '2022-08-14 10:00:00'),
(3, 'start', '2022-08-06 10:00:00'),
(2, 'stop', '2022-08-24 10:00:00'),
(2, 'start', '2022-08-17 10:00:00'),
(5, 'start', '2022-08-14 21:00:00');