本文主要是介绍牛客网SQL160,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
国庆期间每类视频点赞量和转发量_牛客题霸_牛客网
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') dtfrom tb_user_video_logwhere date_format(start_time,'%Y-%m-%d') between '2021-09-25' and '2021-10-03'
) a
join
(select video_id,tagfrom 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的格式
这篇关于牛客网SQL160的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!