with t_loc as
(
select '将台西中关村电子城' loc
union all
select '将台西凯德广场'
union all
select '将西台北京机床研究所'
union all
select '将西台天启大厦'
union all
select '中关村电子城将台西'
union all
select '凯德广场将台西'
union all
select '北京机床研究所将西台'
union all
select '天启大厦将西台'
)
,
t_main as
(
select user_id,start_time
from hello_bike_riding_rcd
where concat(start_loc,end_loc) in
(select loc from t_loc)
),
t_user as
(
select user_id,mon
from (
select user_id,substr(start_time,1,7) mon,count(distinct substr(start_time,1,10)) cnt
from t_main
group by user_id,substr(start_time,1,7)
)t1
where cnt >=5
),
t_row as
(
select user_id
from
(
select user_id,substr(DATE_SUB(STR_TO_DATE(CONCAT(mon, '-01'), '%Y-%m-%d'), INTERVAL rk MONTH),1,7) mon ,count(*) cnt
from
(select user_id,mon,row_number()over(partition by user_id order by mon) rk
from t_user
) t1
group by user_id,substr(DATE_SUB(STR_TO_DATE(CONCAT(mon, '-01'), '%Y-%m-%d'), INTERVAL rk MONTH),1,7)
) t2
where cnt >=3
)
select t1.user_id
,if(t2.user_id is null ,0,1) active_tag
from hello_bike_riding_rcd t1 left join t_row t2 on t1.user_id = t2.user_id
group by t1.user_id,if(t2.user_id is null ,0,1)
with t_loc as
(
select loc_nm,
case when loc_nm = '将台西' then '地铁站'
when loc_nm = '北京机床研究所' then '写字楼'
else loc_type end loc_type
from gd_loc_map
)
,
t_main as
(
select t1.*,t2.loc_type start_type ,t3.loc_type end_type
from hello_bike_riding_rcd t1
left join t_loc t2 on t1.start_loc = t2.loc_nm
left join t_loc t3 on t1.end_loc = t3.loc_nm
where concat(t2.loc_type ,'-',t3.loc_type) in ('写字楼-地铁站','地铁站-写字楼')
),
t_user as
(
select user_id,mon
from (
select user_id,substr(start_time,1,7) mon,count(distinct substr(start_time,1,10)) cnt
from t_main
group by user_id,substr(start_time,1,7)
)t1
where cnt >=5
),
t_row as
(
select user_id
from
(
select user_id,substr(DATE_SUB(STR_TO_DATE(CONCAT(mon, '-01'), '%Y-%m-%d'), INTERVAL rk MONTH),1,7) mon ,count(*) cnt
from
(select user_id,mon,row_number()over(partition by user_id order by mon) rk
from t_user
) t1
group by user_id,substr(DATE_SUB(STR_TO_DATE(CONCAT(mon, '-01'), '%Y-%m-%d'), INTERVAL rk MONTH),1,7)
) t2
where cnt >=3
)
select t1.user_id
,if(t2.user_id is null ,0,1) active_tag
from hello_bike_riding_rcd t1 left join t_row t2 on t1.user_id = t2.user_id
group by t1.user_id,if(t2.user_id is null ,0,1)
with t_loc as
(
select loc_nm,
case when loc_nm = '将台西' then '地铁站'
when loc_nm = '北京机床研究所' then '写字楼'
else loc_type end loc_type
from gd_loc_map
)
,
t_main as
(
select t1.*,t2.loc_type start_type ,t3.loc_type end_type
from hello_bike_riding_rcd t1
left join t_loc t2 on t1.start_loc = t2.loc_nm
left join t_loc t3 on t1.end_loc = t3.loc_nm
),
t_user as
(
select user_id,substr(start_time,1,7) mon
from t_main
where concat(start_type,'-',end_type) in ('写字楼-地铁站','地铁站-写字楼')
group by user_id,substr(start_time,1,7)
having count(distinct substr(start_time,1,10))>=5
),
t_row as
(
select user_id,mon
from
(select user_id,substr(DATE_SUB(STR_TO_DATE(CONCAT(mon, '-01'), '%Y-%m-%d'), INTERVAL rk MONTH),1,7) mon
from
(select user_id,mon,row_number()over(partition by user_id order by mon) rk
from t_user
) t1
) t2
group by user_id,mon
having count(*)>=3
)
select t1.user_id
,if(t2.user_id is null ,0,1) active_tag
from hello_bike_riding_rcd t1 left join t_row t2 on t1.user_id = t2.user_id
group by t1.user_id,if(t2.user_id is null ,0,1)
with t_loc as
(
select loc_nm,if(loc_nm = '将台西','地铁站',loc_type) loc_type from gd_loc_map
)
,
t_main as
(
select t1.*,t2.loc_type start_type ,t3.loc_type end_type
from hello_bike_riding_rcd t1
left join t_loc t2 on t1.start_loc = t2.loc_nm
left join t_loc t3 on t1.end_loc = t3.loc_nm
),
t_user as
(
select user_id,substr(start_time,1,7) mon
from t_main
where concat(start_type,'-',end_type) in ('写字楼-地铁站','地铁站-写字楼')
group by user_id,substr(start_time,1,7)
having count(distinct substr(start_time,1,10))>=5
),
t_row as
(
select user_id,mon
from
(select user_id,substr(DATE_SUB(STR_TO_DATE(CONCAT(mon, '-01'), '%Y-%m-%d'), INTERVAL rk MONTH),1,7) mon
from
(select user_id,mon,row_number()over(partition by user_id order by mon) rk
from t_user
) t1
) t2
group by user_id,mon
having count(*)>=3
)
select t1.user_id
,if(t2.user_id is null ,0,1) active_tag
from hello_bike_riding_rcd t1 left join t_row t2 on t1.user_id = t2.user_id
group by t1.user_id,if(t2.user_id is null ,0,1)
with t_main as
(
select t1.*,t2.loc_type start_type ,t3.loc_type end_type
from hello_bike_riding_rcd t1
left join gd_loc_map t2 on t1.start_loc = t2.loc_nm
left join gd_loc_map t3 on t1.end_loc = t3.loc_nm
),
t_user as
(
select user_id,substr(start_time,1,7) mon
from t_main
where concat(start_type,'-',end_type) in ('写字楼-地铁站','地铁站-写字楼')
group by user_id,substr(start_time,1,7)
having count(distinct substr(start_time,1,10))>=5
),
t_row as
(
select user_id,mon
from
(select user_id,substr(DATE_SUB(STR_TO_DATE(CONCAT(mon, '-01'), '%Y-%m-%d'), INTERVAL rk MONTH),1,7) mon
from
(select user_id,mon,row_number()over(partition by user_id order by mon) rk
from t_user
) t1
) t2
group by user_id,mon
having count(*)=3
)
select t1.user_id
,if(t2.user_id is null ,0,1) active_tag
from hello_bike_riding_rcd t1 left join t_row t2 on t1.user_id = t2.user_id
group by t1.user_id,if(t2.user_id is null ,0,1)
with t_main as
(
select t1.*,t2.loc_type start_type ,t3.loc_type end_type
from hello_bike_riding_rcd t1
left join gd_loc_map t2 on t1.start_loc = t2.loc_nm
left join gd_loc_map t3 on t1.end_loc = t3.loc_nm
),
t_user as
(
select user_id,substr(start_time,1,7) mon
from t_main
where concat(start_type,'-',end_type) in ('写字楼-地铁站','地铁站-写字楼')
group by user_id,substr(start_time,1,7)
having count(distinct substr(start_time,1,10))>=5
),
t_row as
(
select user_id,mon
from
(select user_id,substr(DATE_SUB(STR_TO_DATE(CONCAT(mon, '-01'), '%Y-%m-%d'), INTERVAL rk MONTH),1,7) mon
from
(select user_id,mon,row_number()over(partition by user_id order by mon) rk
from t_user
) t1
) t2
group by user_id,mon
having count(*)>=3
)
select t1.user_id
,if(t2.user_id is null ,0,1) active_tag
from hello_bike_riding_rcd t1 left join t_row t2 on t1.user_id = t2.user_id
group by t1.user_id,if(t2.user_id is null ,0,1)
with t_main as
(
select t1.*,t2.loc_type start_type ,t3.loc_type end_type
from hello_bike_riding_rcd t1
left join gd_loc_map t2 on t1.start_loc = t2.loc_nm
left join gd_loc_map t3 on t1.end_loc = t3.loc_nm
),
t_user as
(
select user_id,substr(start_time,1,7) mon
from t_main
where concat(start_type,'-',end_type) in ('写字楼-地铁站','地铁站-写字楼')
group by user_id,substr(start_time,1,7)
having count(distinct substr(start_time,1,10))>=5
),
t_row as
(
select user_id,mon
from
(select user_id,substr(DATE_SUB(STR_TO_DATE(CONCAT(mon, '-01'), '%Y-%m-%d'), INTERVAL 1 MONTH),1,7) mon
from
(select user_id,mon,row_number()over(partition by user_id order by mon) rk
from t_user
) t1
) t2
group by user_id,mon
having count(*)>=3
)
select t1.user_id
,if(t2.user_id is null ,0,1) active_tag
from hello_bike_riding_rcd t1 left join t_row t2 on t1.user_id = t2.user_id
group by t1.user_id,if(t2.user_id is null ,0,1)
with t_main as
(
select t1.*,t2.loc_type start_type ,t3.loc_type end_type
from hello_bike_riding_rcd t1
left join gd_loc_map t2 on t1.start_loc = t2.loc_nm
left join gd_loc_map t3 on t1.start_loc = t3.loc_nm
),
t_user as
(
select user_id,substr(start_time,1,7) mon
from t_main
where concat(start_type,'-',end_type) in ('写字楼-地铁站','地铁站-写字楼')
group by user_id,substr(start_time,1,7)
having count(distinct substr(start_time,1,10))>=5
),
t_row as
(
select user_id,mon
from
(select user_id,substr(DATE_SUB(STR_TO_DATE(CONCAT(mon, '-01'), '%Y-%m-%d'), INTERVAL 1 MONTH),1,7) mon
from
(select user_id,mon,row_number()over(partition by user_id order by mon) rk
from t_user
) t1
) t2
group by user_id,mon
having count(*)>=3
)
select t1.user_id
,if(t2.user_id is null ,0,1) active_tag
from hello_bike_riding_rcd t1 left join t_row t2 on t1.user_id = t2.user_id
group by t1.user_id,if(t2.user_id is null ,0,1)