我被困在中间 所以我放置了代表我的数据设置的样本数据 MAP和NET_P是相同的
DROP TABLE #TEMP_O
CREATE TABLE #TEMP_O
([A] INT, [B] INT, [RESET] INT, [P] NUMERIC(22,6), [MAP] NUMERIC(22,6), [NET_P] NUMERIC(22,6), [MAP_PER] INT, [PRICE_RESET] INT, [RESET_P_VALUE] INT, [PRICE] NUMERIC(22,6), [PT] INT)
;
INSERT INTO #TEMP_O
([A], [B], [RESET], [P], [MAP], [NET_P], [MAP_PER], [PRICE_RESET], [RESET_P_VALUE], [PRICE], [PT])
VALUES
(1404592, 1, NULL, '39', '165.18', '165.18', 1, 1, 50, 39, 10),
(1404592, 2, NULL, '39', '165.18', '165.18', 1, 1, 50, 39, 10),
(1404592, 3, NULL, '39', '165.18', '165.18', 1, 1, 50, 39, 10),
(1404592, 4, NULL, NULL, NULL, NULL, 1, 2, 60, 42, 10),
(1404592, 5, NULL, NULL, NULL, NULL, 1, 2, 60, 48, 10),
(1404592, 6, NULL, NULL, NULL, NULL, 2, 3, 60, 49, 10),
(1404592, 7, NULL, NULL, NULL, NULL, 2, 3, 70, 56, 10),
(1404592, 8, NULL, NULL, NULL, NULL, 2, 3, 70, 65, 10),
(1404592, 9, NULL, NULL, NULL, NULL, 2, 4, 70, 69, 10),
(1404676, 1, NULL, '70', '165.18', '165.18', 1, 1, 52, 70, 10),
(1404676, 2, NULL, '70', '165.18', '165.18', 1, 1, 52, 79, 10),
(1404676, 3, NULL, '70', '165.18', '165.18', 1, 1, 52, 89, 10),
(1404676, 4, NULL, NULL, NULL, NULL, 2, 2, 56, 90, 10),
(1404676, 5, NULL, NULL, NULL, NULL, 2, 2, 56, 97, 10),
(1404676, 6, NULL, NULL, NULL, NULL, 2, 2, 56, 97, 10),
(1404676, 7, NULL, NULL, NULL, NULL, 3, 3, 63, 98, 10),
(1404676, 8, '1', NULL, NULL, NULL, 4, 4, 63, 98, 10),
(1404676, 9, NULL, NULL, NULL, NULL, 4, 4, 63, 99, 10)
;
我得到了结果但是我花时间使用循环。 需要像下面这样的结果
所需的输出如下。