我想在一个ntile(3)中创建一个ntile(3)。我有以下表格:
Customer | Total_amt | Digital_amt | 1 | 100 | 45 | 2
---|---|---|
200 | 150 | |
3 | 150 | 23 |
300 | 100 | |
350 | 350 | |
112 | 10 | |
312 | 15 | |
260 | 160 | |
9 | 232 | 150 |
190 | 132 |
您是否尝试在子查询中嵌套第一个NTILE,然后将其结果用作下一个NTILE中的分区?如,
SELECT
Customer,
Total_amt,
Digital_amt,
TOTAL_NTILE,
NTILE(3) OVER(
PARTITION BY TOTAL_NTILE
ORDER BY
Digital_Amt
) AS DIGITAL_NTILE
FROM
(
SELECT
Customer,
Total_amt,
Digital_amt,
NTILE(3) OVER(
ORDER BY
Total_amt
) AS TOTAL_NTILE
FROM
table
) rs