SQL与前一个结果聚合



我有以下表格

<表类> 台北 Year2 价值 tbody><<tr>201420141201420142201420153201420164201520155201520166201520177201520178

先在组中聚合,然后使用窗口聚合:

WITH CTE AS(
SELECT Year1,
Year2,
SUM([Value]) AS [Value]
FROM dbo.YourTable
GROUP BY Year1,
Year2)
SELECT Year1,
Year2,
SUM([Value]) OVER (PARTITION BY Year1 ORDER BY Year2) AS [Value]
FROM CTE;

相关内容

  • 没有找到相关文章

最新更新