Sql 表中上次更新的项

Sql 表中上次更新的项,sql,tsql,select,group-by,greatest-n-per-group,Sql,Tsql,Select,Group By,Greatest N Per Group,需要T-SQL才能获得结果 UniqueIndex Item 521 ABC 520 ABC 519 ABC 518 ABC 517 CDC 516 CDC 515

需要T-SQL才能获得结果

UniqueIndex         Item
521                          ABC
520                          ABC
519                          ABC
518                          ABC
517                          CDC
516                          CDC
515                          CDC

对于此2列数据集,您只需使用聚合:

521               ABC
517              CDC
如果要显示更多列,则可以使用子查询进行筛选:

select item, max(uniqueIndex) lastUniqueIndex
from mytable
group by item

这里的性能,考虑一个索引<代码>(项目,UNIQUAL索引)< /代码> ./P> 您还可以使用窗口功能:

select t.*
from mytable t
where t.uniqueIndex = (select max(t1.uniqueIndex) from mytable t1 where t1.item = t.item)

对于此2列数据集,您只需使用聚合:

521               ABC
517              CDC
如果要显示更多列,则可以使用子查询进行筛选:

select item, max(uniqueIndex) lastUniqueIndex
from mytable
group by item

这里的性能,考虑一个索引<代码>(项目,UNIQUAL索引)< /代码> ./P> 您还可以使用窗口功能:

select t.*
from mytable t
where t.uniqueIndex = (select max(t1.uniqueIndex) from mytable t1 where t1.item = t.item)

谢谢对不起,我忘了提到桌子上还有其他的列。对不起,我忘了提到表还有其他列