我有以下 CTE 表达式:
WITH DocDetails_CTE
AS
(
SELECT d.DocumentId,
dd.AutUser,
rank() over (order by d.DocumentId) as [r]
FROM Document d
INNER JOIN DocumentItems di
ON d.DocumentId = di.DocumentId
INNER JOIN DocumentDetails dd
ON dd.DocumentDetailsId = di.DocDetailsId
)
SELECT *
FROM DocDetails_CTE
它返回以下结果:
documentId| AuthUser | [r]
-------------------------------
52 Derck 1
52 John 1
53 Niall 3
53 Bill 3
53 John 3
53 Andy 3
54 Rob 7
54 Noel 7
如何修改 CTE,以便我只获得具有新 documentId 的第一行,例如
documentId| AuthUser | [r]
-------------------------------
52 Derck 1
53 Niall 3
54 Rob 7