当前位置:网站首页>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;
边栏推荐
- iptables 基础配置
- HCIP BGP built adjacent experiment
- 华为防火墙-1-安全区域
- 知识蒸馏Knownledge Distillation
- SECURITY DAY06 ( iptables firewall, filter table control, extended matching, typical application of nat table)
- 已解决EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
- 八股文之redis
- 每日sql - 判断+聚合
- grep、sed、awk
- mmdetection的安装和训练、测试didi数据集的步骤(含结果)
猜你喜欢
随机推荐
pytorch调整模型学习率
iptables 使用脚本来管理规则
HCIP BGP neighbor building, federation, and aggregation experiments
Numpy_备注
HCIP实验(pap、chap、HDLC、MGRE、RIP)
华为防火墙-2-状态检测与会话
HCIP experiments (pap, chap, HDLC, MGRE, RIP)
命令输出给变量
OA项目之会议通知(查询&是否参会&反馈详情)
概念名词解释
使用路由器DDNS功能+动态公网IP实现外网访问(花生壳)
HCIP BGP built adjacent experiment
MySQL导入导出&视图&索引&执行计划
Eight-legged text of mysql
八股文之jvm
[损失函数]——均方差
MySQL之CRUD
每日sql - 判断+聚合
八股文之redis
华为防火墙-5-NAT