一、行转列
公式:1— group by
2—sum(case when 或 if)
二、连续N天登录
hive:
1、distinct
2、row_number(分组排序 序列号)
3、date_sub(日期、序列)
4、grouop by 用户,临时日期
5、having cnt>=N天
6、distinct 去重复
mysql:
1、distinct
2、@rank:=if(@name1 = name ,@rank+1,1) rank,@name1 := name
3、subdate(A、B) temp
4、grouop by 用户,临时日期
5、having cnt>=N天
6、distinct 去重复
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WSFeUd2c-1678976351453)(111111#pic_center)]
SELECT DISTINCT name FROM (SELECT t3.name, t3.temp, count(1) cn FROM (SELECT *, SUBDATE(t2.date,t2.rank) temp from (SELECT name, date, @rank:=if(@name1 = name ,@rank+1,1) rank, @name1 := name from (select DISTINCT name, date from game) t1, (SELECT @rank:=0,@name1:=null) temp ORDER BY name,date asc) t2)t3 GROUP BY t3.name,t3.temp HAVING cn >=3)t4