Sql Oracle,使用窗口/列组功能对行进行分组

Sql Oracle,使用窗口/列组功能对行进行分组,sql,oracle,Sql,Oracle,这是我的问题 Select SalesPerson.SalesPersonName, TimeTable.month, sum(SalesPerson_sales) SUM_OF_SALES From SalesPerson Join SalesRecordTable on SalesRecordTable.SalesPerson_id=SalesPerson.SalesPerson_id Join TimeTable on TimeTable.time_id = SalesRecordTabl

这是我的问题

Select SalesPerson.SalesPersonName, TimeTable.month,
sum(SalesPerson_sales) SUM_OF_SALES
From SalesPerson
Join SalesRecordTable on SalesRecordTable.SalesPerson_id=SalesPerson.SalesPerson_id
Join TimeTable on TimeTable.time_id = SalesRecordTable.time_id
Group by SalesPersonName , TimeTable.month  with rollup 
order by SalesPersonName
哪一个在生产

SalesPersonName month                        TotalSales
NULL             NULL                          565238.13
Andy             1                         15966.75
Andy             2                         10723.32
Andy             3                         17174.77
Andy             4                         9911.38
Andy             5                         12380.12
Andy             6                         12194.56
Andy             7                         18964.82
(more records not pasted here, it basically goes upto month 12, then the records for other sales people follow)
我实际上想做的是得到这样的东西

SalesPersonName month       TotalSales

Andy            3        71762
Andy            6        34486
Andy            9        31738
Andy            12       21532
John            3        23323
John            6         32873
基本上,我想使用SQLOLAP特性对每个销售人员的每3个月销售额进行汇总,并如上所示

我试图使用Range或Rows子句,但我在这里遗漏了一些东西:如下所示

Select SalesPerson.SalesPersonName, TimeTable.month,
    sum(SalesPerson_sales) SUM_OF_SALES OVER ( order by month rows 2 preceding)
    From SalesPerson
    Join SalesRecordTable on SalesRecordTable.SalesPerson_id=SalesPerson.SalesPerson_id
    Join TimeTable on TimeTable.time_id = SalesRecordTable.time_id
    Group by SalesPersonName , TimeTable.month  with rollup 
    order by SalesPersonName
但这是给我的

SalesPersonName     month   (No column name)
Andy                1   1
Andy                    1   2.06
Andy                    1   3.14
Andy                    1   3.26
, thousands of records follow :(
如何修复上面的查询以获得所需的结果?我想我需要以某种方式修复前面的第2行,它将根据需要工作


非常感谢您的输入

您可以使用窗口函数,但我认为您可以只按CEILmonth/3进行分组。

谢谢,但我真的很想修复rwos 2前面的部分。在这里,您真的不需要汇总、分析函数和其他奇特的功能。如下文所述,您只需回答“每月一次”即可获得所需结果。