我有一个表是这样的:如何将表格中的最新日期和ID分组?
我需要这组最新表日期为每一个ID。 我的意思是,我想得到最后一行每个ID。以下是我的查询:
SELECT DISTINCT ch.Date,ID FROM dbo.tblrisk AS rk
inner join (Select TableIdentity, [Date] from tblCommonHistory) ch
ON ch.TableIDentity = rk.ID order by ID
我该怎么做我想要的?
编辑:此查询工作对我来说:
SELECT DISTINCT ch.dt,ID FROM dbo.tblrisk AS rk
inner join (Select TableIdentity, max([Date]) as dt from tblCommonHistory group by TableIdentity) ch ON ch.TableIDentity = rk.ID order by ID
显示我们预期的结果(给定样本数据如上)。 – jarlh