Tôi nghĩ điều này sẽ làm những gì bạn muốn.
;WITH X1
AS
(
SELECT SomeDateTime
,GroupID
,ID
,ROW_NUMBER() OVER (PARTITION BY GroupID
ORDER BY SomeDateTime DESC
) AS rn
FROM X
)
SELECT SomeDateTime
,GroupID
,ID
FROM X1
WHERE rn = 1