更改数据捕获 - 仅获取不同的最新更改

Change Data Capture- Get only distinct latest changes

我试图仅从某个变更数据捕获中查找所有不同的和最新的变更 table。这是 table 的快照。

我尝试使用这个查询:

select DISTINCT StudentUSI, sys.fn_cdc_map_lsn_to_time(__$start_lsn) TransactionTime, __$operation Operation, LastModifiedDate 
from cdc.Student_CT
where __$operation in (1,2,4)
ORDER BY StudentUSI;

但是返回的结果是:

此外,如果我尝试使用 GROOUP BY,它会显示:

Column 'cdc.Student_CT.__$start_lsn' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

有没有其他方法可以获得关于 StudentUSI 值的最新更改? 谢谢!

使用row_number()

select * from 
(select DISTINCT StudentUSI, sys.fn_cdc_map_lsn_to_time(__$start_lsn) TransactionTime, __$operation Operation, LastModifiedDate ,row_number() over(partition by StudentUSI order by LastModifiedDate desc) as rn
from cdc.Student_CT
where __$operation in (1,2,4))a where rn=1