Sql 使用Group by和PREVICER对()求和

Sql 使用Group by和PREVICER对()求和,sql,sum,hiveql,window-functions,Sql,Sum,Hiveql,Window Functions,我有一个很好用的代码——只需按电话使用情况列出日期 select date, data, SUM(data) OVER (ORDER BY date asc ROWS between 30 PRECEDING and current row) data_30, texts, SUM(tests) OVER (ORDER BY date asc

我有一个很好用的代码——只需按电话使用情况列出日期

select  date,
        data,
        SUM(data) OVER (ORDER BY date asc
                            ROWS between 30 PRECEDING and current row) data_30,
        texts,
        SUM(tests) OVER (ORDER BY date asc
                ROWS between 30 PRECEDING and current row) text_30,
        voice,
        SUM(voice) OVER (ORDER BY date asc
                ROWS between 30 PRECEDING and current row) voice_30,
        wifi,
        SUM(wifi) 
                OVER (ORDER BY date asc
                ROWS between 30 PRECEDING and current row) wifi_30
    FROM Table
我只是想知道如何使用前30天的总和,但是否有可能包含第二个变量,比如,我想看看日期,按这些用法的费率计划

差不多

select  date,
        plan, b, c, d, 
        data,
        SUM(data) OVER (ORDER BY date asc
                            ROWS between 30 PRECEDING and current row) data_30,
        texts,
        SUM(tests) OVER (ORDER BY date asc
                ROWS between 30 PRECEDING and current row) text_30,
        voice,
        SUM(voice) OVER (ORDER BY date asc
                ROWS between 30 PRECEDING and current row) voice_30,
        wifi,
        SUM(wifi) 
                OVER (ORDER BY date asc
                ROWS between 30 PRECEDING and current row) wifi_30
    FROM Table
    group by date, plan, b, c, d

公正日期的结果

date  usage  last30sum
1/1   1       1
1/2   1       2
....
1/20  1       30
如果我有

date line     rateplan        usage  
1/1  phone1   10gbplan        1
1/1  phone2   unlimited       2                
1/2  phone3   10gbplan        1                
....
1/30 phone200 10gbplan        1                
我想看看事情的进展

date plan        totalusage   rolling_30
1/2  10gbplan   1            4+ sum(28 days before 1/2)

你能按日期分组吗,unl得到最后30天的unl,a,b,c只是指其他分组,可以像按设备型号,或区域

我通过在分区中添加

select  date,
        plan, b, c, d, 
        data,
        SUM(data) OVER (partition by plan, b, c, d
                        ORDER BY date asc
                            ROWS between 30 PRECEDING and current row) data_30,
        texts,
        SUM(tests) OVER (partition by plan, b, c, d
                ORDER BY date asc
                ROWS between 30 PRECEDING and current row) text_30,
        voice,
        SUM(voice) OVER (partition by plan, b, c, d
                ORDER BY date asc
                ROWS between 30 PRECEDING and current row) voice_30,
        wifi,
        SUM(wifi) 
                OVER (partition by plan, b, c, d
                ORDER BY date asc
                ROWS between 30 PRECEDING and current row) wifi_30
    FROM Table

样本数据和预期结果将有所帮助。什么是
计划
?什么是
b
c
d
?你为什么聚集在一起?@GordonLinoff,又来了!!我贴了一些例子@戈登林诺夫,我相信,我可能已经通过写例子解决了这个问题。