1. 题目需求
从订单详情表(order_detail)中,求出商品连续售卖的时间区间
结果如下(截取部分):
2. 需要用到的表
订单明细表:order_detail
3. 查询sql
select
A.sku_id,
min(A.create_date) as start_date,
max(A.create_date) as end_date
from
(select
sku_id, create_date,
(date_sub(create_date , dense_rank()over(partition by sku_id order by create_date))) as dd2
from order_detail )A
group by A.sku_id,A.dd2