最高峰用时直播人数

an anonymous user · March 05, 2025
CREATE TABLE IF NOT EXISTS t1_livestream_log (
    user_id INT, -- 主播ID
    start_time VARCHAR(19), -- 开始时间
    end_time VARCHAR(19) -- 结束时间
);

INSERT INTO t1_livestream_log (user_id, start_time, end_time) VALUES 
(1,'2024-04-29 01:00:00','2024-04-29 02:01:05'),
(2,'2024-04-29 01:05:00','2024-04-29 02:03:18'),
(3,'2024-04-29 02:00:00','2024-04-29 04:03:22'),
(4,'2024-04-29 03:15:07','2024-04-29 04:33:21'),
(5,'2024-04-29 03:34:16','2024-04-29 06:10:45'),
(6,'2024-04-29 05:22:00','2024-04-29 07:01:08'),
(7,'2024-04-29 06:11:03','2024-04-29 09:26:05'),
(3,'2024-04-29 08:00:00','2024-04-29 12:34:27'),
(1,'2024-04-29 11:00:00','2024-04-29 16:03:18'),
(8,'2024-04-29 15:00:00','2024-04-29 17:01:05');


select max(sum1)  as max_online_cnt from(
select user_id, act_time, sum(ct) over (order by act_time asc) as sum1 from
((select user_id, start_time as act_time, 1 as ct from t1_livestream_log)
union all
(select user_id, end_time as act_time, -1 as ct from t1_livestream_log)) as t2
) as t3


























Output

Comments

Please sign up or log in to contribute to the discussion.