首页 > 其他 > 详细

hive 7天内连续3天

时间:2021-08-10 16:41:31      阅读:24      评论:0      收藏:0      [点我收藏+]
select
    store_id
    ,date_diff
    ,count(*)
from (
    SELECT
        store_id
        ,date_sub(order_bill_date,rk) date_diff
    from (
        SELECT 
            store_id
            ,order_bill_date
            ,rank() over(partition by store_id order by order_bill_date) rk
        FROM (
            SELECT store_id,substr(order_bill_date,1,10) as order_bill_date
            from xxx
            WHERE dt = 2021-08-08
            and store_id is not null
            --AND 时间范围
            group by store_id,substr(order_bill_date,1,10)
        ) as ori
    ) as t1
) as t2
group by store_id,date_diff
having count(*) >= 7



SELECT id,
       count(*)
FROM(
    SELECT *,
          date_sub(substr(日期,1,10),cum)AS 结果
   FROM (
        SELECT *,
             rank() over(PARTITION BY id
                               ORDER BY 日期) AS cum
        FROM (
            SELECT DISTINCT substr(order_bill_date,1,10) AS 日期 ,store_id AS id
            FROM xxx
            WHERE dt = 2021-08-08 
        ) AS a
    ) AS b
) AS c
GROUP BY id,结果
HAVING count(*)>=7

 

hive 7天内连续3天

原文:https://www.cnblogs.com/yuan66/p/15123495.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!