sql - SQL - 只需要最大日期的记录
解决方案
使用row_number()
with top (1) with ties
available for SQL Server(最初被标记):
select top (1) with ties t.*
from table t
order by row_number() over (partition by no order by date desc);
您还可以使用子查询:
select t.*
from (select t.*, row_number() over (partition by no order by date desc) as seq
from table t
) t
where seq = 1;
推荐阅读
- java-8 - 如何使用 Java 8 将 List 转换为 HashBasedTable?
- f# - F# 代码引用:我可以定义自己的具体和抽象语法吗?
- arrays - 如何更新主 CPLEX 中的数组数据
- ssl - 无法在某些 url 上提取证书组织
- functional-programming - 在 Elixir 中转换地图列表
- spring - RestController 为 GetMapping 设置默认标头
- junit4 - 当@before 部分中的代码失败时,Junit 会执行@Test 用例吗?
- html - 隐藏 URL 仅显示域
- javascript - 如何从 TypeScript 对象中获取数据?
- android - 如何使用转换工厂自动映射errorBody?