T-SQL select 到 temp table 没有正确的结果
T-SQL select into temp table does not have correct result
-- 这个结果是正确的并且工作正常:
SELECT AutoId, Name,[Group],[Priority], SUMCalculatedPercent
FROM
(SELECT DISTINCT *,
ROW_NUMBER() OVER
(
PARTITION BY [Group] ORDER BY SUMCalculatedPercent DESC,[Priority]
)
AS ranker
FROM #GroupMasterNameChoose
)Z
WHERE ranker = 1
ORDER BY Z.SUMCalculatedPercent DESC,Z.[Priority]
-- 这个结果是错误的:
SELECT AutoId, Name,[Group],[Priority], SUMCalculatedPercent
INTO #GroupOwner
FROM
(SELECT DISTINCT *,
ROW_NUMBER() OVER
(
PARTITION BY [Group] ORDER BY SUMCalculatedPercent DESC,[Priority]
)
AS ranker
FROM #GroupMasterNameChoose
)Z
WHERE ranker = 1
ORDER BY Z.SUMCalculatedPercent DESC,Z.[Priority]
--
问题:我需要将正确的结果存储到 Temp Table
移除 ORDER BY Z.SUMCalculatedPercent DESC,Z.[Priority]
-- 这个结果是正确的并且工作正常:
SELECT AutoId, Name,[Group],[Priority], SUMCalculatedPercent
FROM
(SELECT DISTINCT *,
ROW_NUMBER() OVER
(
PARTITION BY [Group] ORDER BY SUMCalculatedPercent DESC,[Priority]
)
AS ranker
FROM #GroupMasterNameChoose
)Z
WHERE ranker = 1
ORDER BY Z.SUMCalculatedPercent DESC,Z.[Priority]
-- 这个结果是错误的:
SELECT AutoId, Name,[Group],[Priority], SUMCalculatedPercent
INTO #GroupOwner
FROM
(SELECT DISTINCT *,
ROW_NUMBER() OVER
(
PARTITION BY [Group] ORDER BY SUMCalculatedPercent DESC,[Priority]
)
AS ranker
FROM #GroupMasterNameChoose
)Z
WHERE ranker = 1
ORDER BY Z.SUMCalculatedPercent DESC,Z.[Priority]
-- 问题:我需要将正确的结果存储到 Temp Table
移除 ORDER BY Z.SUMCalculatedPercent DESC,Z.[Priority]