SQL题请教~

表:商品id:id
销售日期:date
销售额较前一天的增长率:rate
怎么求连续三天增长率超过50%的商品呢?
输出:id和date

没有思路,请教各位指点一下~感谢

#笔试题目##MySQL#
全部评论
select id from (select *,sum(case when datediff(date-lag_date)<=1 and rate>=0.5 and lag_rate>=0.5 then 0 else 1                   end) over(partiton by id rows between unbounded preceding and current row) as s   from (select id,date,rate,            lag(date,1,null) over(partition by id order by date) as lag_date,            lag(rate,1,null) over(partition by id order by date) as lag_rate            from table)a )tab group by id,s having count(1)>=3
点赞 回复 分享
发布于 2019-08-22 22:34
思路:lag(date)over as lag_date sum(case when datediff(date-lag_date)<=1 and rate>=0.5 then 1 else 0)over()后面取大于等于3的就行
点赞 回复 分享
发布于 2019-08-22 19:20

相关推荐

10-30 10:16
南京大学 Java
龚至诚:给南大✌️跪了
点赞 评论 收藏
分享
hso_:哈哈哈哈哈哈我没offer一样在同一道题开喷了
投递深圳同为数码等公司10个岗位
点赞 评论 收藏
分享
点赞 15 评论
分享
牛客网
牛客企业服务