Hi,As Ifor said, we need a column that indicate the order of the records.So , I added a column ;with aCTE (cID,Name,Val)AS (SELECT 1,'a',200 UNION ALL SELECT 2,'a',400 UNION ALL SELECT 3,'a',700 UNION ALL SELECT 4,'b',100 UNION ALL SELECT 5,'b',150 UNION ALL SELECT 6,'b',50 UNION ALL SELECT 7,'c',80 UNION ALL SELECT 8,'c',40 UNION ALL SELECT 9,'c',200 UNION ALL SELECT 10,'c',220 )SELECT B.Name ,B.Val FROM ( SELECT A.* , MIN(CASE WHEN A.Val>= ISNULL(prevRow.Val,A.Val) THEN 1 ELSE 0 END) OVER(PARTITION BY A.Name ORDER BY A.cID ASC) AS minID FROM aCTE AS A OUTER APPLY ( SELECT TOP (1) * FROM aCTE AS B WHERE A.Name = B.Name AND A.cID > B.cID ORDER BY B.cID DESC) AS prevRow )BWHERE B.minID = 1
and the output:a 200a 400a 700b 100b 150c 80
sabinWeb MCP