1

我正在尝试选择几个不同的总和,其中之一是OVER (Partition by column_also_in_select_plan).

但是,我似乎永远无法GROUP BY正确声明。

例子:

Select 1, 2, 3, sum(4) over (partition by 3), sum(case when 6 = etc...) 
FROM table
Where filters
GROUP BY ?

感谢您的任何提示:)

4

1 回答 1

0

同时进行聚合和使用窗口函数并没有多大意义,所以我并不奇怪你会感到困惑。在上面的示例中,您可能希望将窗口移动到外部查询,即:

select 1, 2, 3, sum(sum4) over(partition by 3), ...
from (
      select 1, 2, 3, sum(4) as sum4
      from table
      where filters
      group by 1, 2, 3
) x
于 2011-09-01T14:56:04.470 回答