当前位置 : 主页 > 手机开发 > ROM >

持续次数计算逻辑

来源:互联网 收集:自由互联 发布时间:2021-06-10
select t3.day_time ,t3.cnt ,t3.rn1 ,t3.rn2 ,t3.diff ,row_number() over (partition by t3.diff order by t3.day_time) as rn from ( select t2.day_time ,t2.cnt ,t2.rn1 ,t2.rn2 ,rn2 - rn1 as diff from ( select t1.day_time ,t1.cnt ,row_number() ov

 

select
     t3.day_time
    ,t3.cnt
    ,t3.rn1
    ,t3.rn2
    ,t3.diff
    ,row_number() over(partition by t3.diff order by t3.day_time) as rn
from (
    select
         t2.day_time
        ,t2.cnt
        ,t2.rn1
        ,t2.rn2
        ,rn2 - rn1 as diff
    from (
        select
             t1.day_time
            ,t1.cnt
            ,row_number() over(partition by t1.cnt order by t1.day_time) as rn1
            ,row_number() over(order by t1.day_time)                     as rn2
        from (
            select 2019-03-18 19:01:17 as day_time, 100 as cnt union all
            select 2019-03-18 19:01:19 as day_time, 100 as cnt union all
            select 2019-03-18 19:01:21 as day_time, 100 as cnt union all
            select 2019-03-18 19:01:22 as day_time, 5   as cnt union all
            select 2019-03-18 19:01:22 as day_time, 1   as cnt union all
            select 2019-03-18 19:01:24 as day_time, 100 as cnt union all
            select 2019-03-18 19:01:23 as day_time, 100 as cnt
        ) t1
        order by t1.day_time
    ) t2
) t3
;
网友评论