我正在尝试在我的 PARTITION BY 子句中使用浮点数据类型对我的数据使用 NTILE。请原谅人为的例子,但我认为最好的方式来说明我的问题和困惑是通过这段代码:
CREATE TABLE Test
(
Cash float NOT NULL,
Number int NOT NULL
)
GO
INSERT INTO TEST VALUES(1.05,1);
INSERT INTO TEST VALUES(1.368,1);
INSERT INTO TEST VALUES(0.775,1);
INSERT INTO TEST VALUES(1.699,1);
INSERT INTO TEST VALUES(1.599,1);
INSERT INTO TEST VALUES(0.80,1);
INSERT INTO TEST VALUES(0.80,1);
INSERT INTO TEST VALUES(0.994,1);
INSERT INTO TEST VALUES(0.848,1);
INSERT INTO TEST VALUES(0.675,1);
INSERT INTO TEST VALUES(0.575,1);
INSERT INTO TEST VALUES(12.998,1);
INSERT INTO TEST VALUES(1.999,1);
INSERT INTO TEST VALUES(0.65,1);
INSERT INTO TEST VALUES(0.80,1);
INSERT INTO TEST VALUES(2.60,1);
SELECT CASH,
NTILE(3) OVER (PARTITION BY Cash ORDER BY Cash) AS Trio
INTO #Test
FROM Test
我本来希望分组是这样的:
0.575 1
0.65 1
0.675 1
0.775 1
0.8 1
0.8 2
0.8 2
0.848 2
0.994 2
1.05 2
1.368 3
1.599 3
1.699 3
1.999 3
2.6 3
12.998 3
但是,结果集看起来像这样:
CASH Trio
0.575 1
0.65 1
0.675 1
0.775 1
0.8 1
0.8 2
0.8 3
0.848 1
0.994 1
1.05 1
1.368 1
1.599 1
1.699 1
1.999 1
2.6 1
12.998 1
当 max 和 min 按组应用时,范围分组看起来真的很奇怪
SELECT
MAX(CASH), MIN(CASH), Trio
FROM #Test
GROUP BY Trio
MAX MIN TRIO
12.998 0.575 1
0.8 0.8 2
0.8 0.8 3
谁能解释这里发生了什么?