当前位置:网站首页>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;
边栏推荐
猜你喜欢
随机推荐
八股文之并发编程
抖音API接口
《Show and Tell: A Neural Image Caption Generator》论文解读
HCIP OSPF/MGRE Comprehensive Experiment
利用opencv读取图片,重命名。
My approval of OA project (inquiry & meeting signature)
训练分类器
Top20括号匹配
How Xshell connects to a virtual machine
Numpy_备注
Xshell如何连接虚拟机
MySQL之CRUD
HCIP OSPF dynamic routing protocol
华为防火墙-6
iptables 流量统计
HCIA knowledge review
华为防火墙-7-dhcp
类的定义、类的继承以及super的使用
HCIP MGRE\OSPF综合实验
OA项目之我的审批(查询&会议签字)









