sqlsever 在多列都有重复项的情况下,如何查询每组数据创建时间最近的数据;
使用分组函数:ROW_NUMBER() over (partition by 字段名 order by 排序字段 desc)
示例如下:
SQL查询:子查询也可以实现类似效果
SELECT * FROM test a where a.createTime = (select MAX(createTime) from test where id= a.id) and a.one = ‘a’ and a.two = ‘a’;