- select *
- from
- (
- select tag,dt,
- sum(单日点赞量)over(partition by tag order by dt rows between 6 preceding and 0 following),
- max(单日转发量)over(partition by tag order by dt rows between 6 preceding and 0 following)
- from
- (
- select dt,tag,sum(if_like) 单日点赞量,sum(if_retweet) 单日转发量
- from
- (
- select id,video_id,if_like,if_retweet,
- date_format(start_time,'%Y-%m-%d') dt
- from tb_user_video_log
- where date_format(start_time,'%Y-%m-%d') between '2021-09-25' and '2021-10-03'
- ) a
- join
- (
- select video_id,tag
- from tb_video_info
- ) b
- on a.video_id=b.video_id
- group by dt,tag
- ) c
- ) d
- where dt between '2021-10-01' and '2021-10-03'
- order by tag desc,dt
注意点:
1. date_format中%Y和%y好像不一样 ;
2. 注意时间相关的函数,如果想当成数字取用要注意是不是带“-”的,小细节问题,如果带“-”,你和数字直接去比较肯定不一样。
比较的时候一般用between and比较多
3. 认识了mysql中三个时间相关的函数:
convert(start_time,char(10))
date_format(start_time,'%Y-%m-%d')
date(start_time)
结果都是2021-09-25的格式