SQL SERVER查询每组最后一条数据

现有表如下:

 

 需要查询每一个item对应的最后一条数据,SQL SERVER 如下:

   SELECT * FROM (SELECT ROW_NUMBER() OVER(PARTITION BY ItemCode ORDER BY RecordID desc) as RowNum, * from RSItemCostChange ) as H where H.RowNum = 1 ORDER BY ItemCode

 

posted @ 2023-04-07 11:48  明天星期五啦  阅读(853)  评论(0编辑  收藏  举报