sql数据分析案例和学习资料 https://mp.weixin.qq.com/mp/appmsgalbum?action=getalbum&__biz=MzkzMDI3OTgyNw==&scene=1&album_id=2121329846248112133&count=3#wechat_redirect
实战 SQL:亚马逊、京东等电商平台的销售排行榜和飙升榜
Hive 分析函数lead、lag实例应用_没事看看书-优快云博客_hive lead
Hive-SQL查询连续活跃登陆的用户 - 奇遇yms - 博客园
【SQL】查询连续登陆7天以上的用户 - kww - 博客园
3. 求最近一次xx距今的天数sql模板
row_number() over()
datediff()函数
求最近一次的xx,sql模板,例如获取cookie最近一次访问日期
-- step01 先求最近一次的访问时间
with user_cookie_relation as (
select
t.cookie_id as cookieid,
t.last_visit_time as last_date
from (
select cookie_id,
last_visit_time,
row_number() over(partition by cookie_id order by last_visit_time desc) as rank
from ods.page_view_log
where data_date = " start_date_str "
and cookie_id is not null
) t
where t.rank =1
having cookie_id is not null
)
-- step02 利用datediff求具体的天数
insert overwrite table dw.userprofile_action_all partition(data_date="data_date",labelid='${labelid}')
select 'ACTION_C_02_001' as labelid,
cookieid,
datediff(to_date("data_date"),concat(substr(last_date,1,4),'-',substr(last_date,5,2),'-',substr
(last_date,7,2))) as labelweight
from user_cookie_relation # 上一步骤注册的视图
group by 'ACTION_C_02_001', -- 这里的group by用来去重
cookieid,
datediff(to_date("data_date"),concat(substr(last_date,1,4),'-', substr(last_date,5,2),'-',
substr(last_date,7,2)))