这个很难。
RestuarantID |描述
1849 |餐厅\ 1849(1849)
1849 |餐厅\弗朗西斯(1849)
我可以排名,但无法保证说明顺序
SELECT RestuarantID ,
[Description] ,
RANK() OVER(PARTITION BY RestuarantID ORDER BY [Description]) AS MyRank
FROM FinalOutPut
我需要做的是按说明长度排名。
需要删除长度最短的那个。
答案 0 :(得分:1)
尝试
DECLARE @tbl TABLE(id INT, description VARCHAR(100));
INSERT INTO @tbl VALUES(1,'123'),(1,'1234'),(1,'12'),(2,'abc'),(2,'ab');
SELECT * FROM @tbl;
WITH MyCTE AS
(
SELECT ROW_NUMBER() OVER(PARTITION BY ID ORDER BY LEN(Description) DESC) AS Nr
,ID
,Description
FROM @tbl
)
DELETE FROM MyCTE WHERE Nr>1; --will keep just the longest
SELECT * FROM @tbl;