当前位置:网站首页>Find the shops that have sold more than 1,000 yuan per day for more than 30 consecutive days in the past six months
Find the shops that have sold more than 1,000 yuan per day for more than 30 consecutive days in the past six months
2022-08-11 07:13:00 【Eating too much sugar will not gain weight】
Order table T (user_id, shop_id, product_id, price, trans_dt).Q1: Find the shops that have sold more than 1,000 yuan per day for more than 30 consecutive days in the past six months.
//1
select shop_id, f_date,count(1) as days from ( select
*,date_sub(t.trans_dt,rn) as f_date from (select
- ,ROW_NUMBER() over (partition by shop_id order by trans_dt) as rn from ( select shop_id,substr(trans_dt,1,10) as trans_dt,sum(price) as
price from T group by shop_id,substr(trans_dt,1,10) having
sum(price)>1000 ) )a )b group by shop_id, f_date having count(1) >=30
//2
select shop_id from ( select shop_id,trans_dt,lead(trans_dt)
over(partition by shop_id order by price order by trans_dt ) as n_day
from ( select shop_id,substr(trans_dt,1,10) astrans_dt,sum(price) as
price from T group by shop_id,substr(trans_dt,1,10) having
sum(price)>1000 )a )b where datediff(n_day,trans_dt)=1
Q2: 20 random draws
select * from Q1 order by rand() limit 10;
边栏推荐
猜你喜欢
随机推荐
MySQL01
命令输出给变量
Arcgis小工具_实现重叠分析
推荐一个好用的IDEA插件---Translation—中英互译
SECURITY DAY06 ( iptables firewall, filter table control, extended matching, typical application of nat table)
detectron2,手把手教你训练mask_rcnn
OA项目之项目简介&会议发布
皮质-皮质网络的多尺度交流
radix-4 FFT 原理和C语言代码实现
什么是Inductive learning和Transductive learning
OA项目之待开会议&历史会议&所有会议
亚马逊API接口大全
【LeetCode】306.累加数(思路+题解)
Record a Makefile just written
iptables的状态
淘宝API常用接口与获取方式
【LeetCode】1036. 逃离大迷宫(思路+题解)压缩矩阵+BFS
【LeetCode】851.喧闹与富有(思路+题解)
iptables 基础配置
OA Project Pending Meeting & History Meeting & All Meetings