select user_id, max(consecutive_days) as max_consecutive_days
from (select user_id, flag, count(start_dt) as consecutive_days
from (select user_id, start_dt, sum(if(diff = 1, 0, 1)) over (partition by user_id order by start_dt) flag
from (select user_id,
start_dt,
datediff((start_dt), lag(start_dt, 1) over (partition by user_id order by start_dt)) as diff
from (select distinct user_id, date_format(start_time, '%Y-%m-%d') start_dt
from listen_rcd
where song_id in (
select song_id
from song_info a join singer_info b
on a.origin_singer_id = b.singer_id and type3 = '个人'
where b.singer_id in (
select singer_id from album_info
)
)
) listen_rcd) t1) t2
group by user_id, flag) t3
group by user_id
select user_id, max(consecutive_days) as max_consecutive_days
from (select user_id, flag, count(start_dt) as consecutive_days
from (select user_id, start_dt, sum(if(diff = 1, 0, 1)) over (partition by user_id order by start_dt) flag
from (select user_id,
start_dt,
datediff((start_dt), lag(start_dt, 1) over (partition by user_id order by start_dt)) as diff
from (select distinct user_id, date_format(start_time, '%Y-%m-%d') start_dt
from listen_rcd
where song_id in (
select song_id
from song_info a join singer_info b
on a.origin_singer_id = b.singer_id and type3 = '个人' and type2 !='欧美'
)
) listen_rcd) t1) t2
group by user_id, flag) t3
group by user_id
select user_id, max(consecutive_days) as max_consecutive_days
from (select user_id, flag, count(start_dt) as consecutive_days
from (select user_id, start_dt, sum(if(diff = 1, 0, 1)) over (partition by user_id order by start_dt) flag
from (select user_id,
start_dt,
datediff((start_dt), lag(start_dt, 1) over (partition by user_id order by start_dt)) as diff
from (select distinct user_id, date_format(start_time, '%Y-%m-%d') start_dt
from listen_rcd
where song_id in (
select song_id
from song_info a join singer_info b on a.origin_singer_id = b.singer_id and type3 = '个人'
where album_id in (
select album_id
from album_info
)
)
) listen_rcd) t1) t2
group by user_id, flag) t3
group by user_id
select user_id, max(consecutive_days) as max_consecutive_days
from (select user_id, flag, count(start_dt) as consecutive_days
from (select user_id, start_dt, sum(if(diff = 1, 0, 1)) over (partition by user_id order by start_dt) flag
from (select user_id,
start_dt,
datediff((start_dt), lag(start_dt, 1) over (partition by user_id order by start_dt)) as diff
from (select distinct user_id, date_format(start_time, '%Y-%m-%d') start_dt
from listen_rcd
where song_id in (
select song_id
from song_info a join singer_info b on a.origin_singer_id = b.singer_id and type3 = '个人'
join album_info c on a.origin_singer_id = c.singer_id
)
) listen_rcd) t1) t2
group by user_id, flag) t3
group by user_id
with
tmp2 as
(select user_id, max(consecutive_days) as max_consecutive_days
from (select user_id, flag, count(start_dt) as consecutive_days
from (select user_id, start_dt, sum(if(diff = 1, 0, 1)) over (partition by user_id order by start_dt) flag
from (select user_id,
start_dt,
datediff((start_dt), lag(start_dt, 1) over (partition by user_id order by start_dt)) as diff
from (select distinct user_id, date_format(start_time, '%Y-%m-%d') start_dt
from listen_rcd
where song_id in (
select song_id
from song_info a join singer_info b on a.origin_singer_id = b.singer_id
where type3 = '个人'
)
) listen_rcd) t1) t2
group by user_id, flag) t3
group by user_id)
select users.user_id,ifnull(max_consecutive_days,0) as max_consecutive_days
from qqmusic_user_info users left join tmp2
on users.user_id = tmp2.user_id
select user_id, max(consecutive_days) as max_consecutive_days
from (select user_id, flag, count(start_dt) as consecutive_days
from (select user_id, start_dt, sum(if(diff = 1, 0, 1)) over (partition by user_id order by start_dt) flag
from (select user_id,
start_dt,
datediff((start_dt), lag(start_dt, 1) over (partition by user_id order by start_dt)) as diff
from (select distinct user_id, date_format(start_time, '%Y-%m-%d') start_dt
from listen_rcd
where song_id in (
select song_id
from song_info a join singer_info b on a.origin_singer_id = b.singer_id
where type3 = '个人'
)
) listen_rcd) t1) t2
group by user_id, flag) t3
group by user_id
with
tmp2 as
(select user_id, max(consecutive_days) as max_consecutive_days
from (select user_id, flag, count(start_dt) as consecutive_days
from (select user_id, start_dt, sum(if(diff = 1, 0, 1)) over (partition by user_id order by start_dt) flag
from (select user_id,
start_dt,
datediff((start_dt), lag(start_dt, 1) over (partition by user_id order by start_dt)) as diff
from (select distinct user_id, date_format(start_time, '%Y-%m-%d') start_dt
from listen_rcd
) listen_rcd) t1) t2
group by user_id, flag) t3
group by user_id)
select users.user_id,ifnull(max_consecutive_days,0) as max_consecutive_days
from qqmusic_user_info users left join tmp2
on users.user_id = tmp2.user_id
select user_id, max(consecutive_days) as max_consecutive_days
from (select user_id, flag, count(start_dt) as consecutive_days
from (select user_id, start_dt, sum(if(diff = 1, 0, 1)) over (partition by user_id order by start_dt) flag
from (select user_id,
start_dt,
datediff((start_dt), lag(start_dt, 1) over (partition by user_id order by start_dt)) as diff
from (select distinct user_id, date_format(start_time, '%Y-%m-%d') start_dt
from listen_rcd
where song_id in (
select song_id
from song_info a join singer_info b on a.origin_singer_id = b.singer_id
)
) listen_rcd) t1) t2
group by user_id, flag) t3
group by user_id
select user_id,max(consecutive_days) as max_consecutive_days
from
(select user_id,flag,count(start_dt) as consecutive_days
from
(select user_id,start_dt,sum(if(diff=1,0,1)) over(partition by user_id order by start_dt) flag
from
(select user_id,start_dt,datediff((start_dt),lag(start_dt,1) over(partition by user_id order by start_dt) ) as diff
from (selectdistinct user_id,date_format(start_time,'%Y-%m-%d') start_dt from listen_rcd ) listen_rcd
) t1
) t2
group by user_id,flag) t3
group by user_id