我需要在三个不同的组(30%,30%和40%)中对查询结果进行分区。 如果我使用NTILE(3)函数,结果将分为三个等于组(33%,33%,33%)。 我该怎么办?
这是我的查询架构:
;WITH TMP1 AS (
SELECT
Column0,
ISNULL(SUM(Column1),0) AS Val
FROM MyTable
GROUP BY Column0
),
TMP2 AS (
SELECT NTILE (3) OVER (ORDER BY Column0 DESC) AS MyGroup, Val
FROM TMP1
)
SELECT MyGroup, ISNULL(SUM(Val),0) as Val
FROM TMP2
GROUP BY MyGroup
ORDER BY MyGroup
非常感谢
答案 0 :(得分:1)
使用ntile(10)
并(1,2,3)
30%,(4,5,6)
30%,(7,8,9,10)
40%