step1: 查找user_id,会员开始生效时间,并将开始生效时间记为tms,开始生效时,将tag标记为1;

step2:查找user_id,会员生效结束日期,并将结束时间记为tms,结束生效时,将tag标记为-1;

step3:将step1,step2中查找到的数据全连接;

step4:利用窗口函数将所有的日期tms排序后,求和,记为num;

step5:num的最大值记为B站大会员最多同时在线人数。

select max(num) as max_num

from(

select

user_id,

sum(tag) over(order by tms) as num

from(

select

user_id,

begin_date as tms,

1 as tag

from detail_list_tb

union all

select

user_id,

end_date as tms,

-1 as tag

from detail_list_tb

)a1

)a;