现有表如下:
需要查询每一个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