我的查询是计算每6个星期的累计总数。
;WITH CTE_Group AS (
SELECT id, ClientId, extraId, weekCount, Total1,Total2,
(ROW_NUMBER() OVER (PARTITION BY extraId ORDER BY ClientId,weekCount) + 5) / 6 AS grp
FROM Sale
)
SELECT id, id, ClientId, extraId, weekCount, Total1,Total2,
SUM(Total1+Total2) OVER (PARTITION BY extraId, grp ORDER BY ClientId,weekCount)
FROM CTE_Group
但它显示"语法接近顺序"。
提前致谢!!