![](/img/trans.png)
[英]SQL (Oracle) to query for record with max date, only if the end_dt has a value
[英]SQL - Only need the record with Max Date
将row_number()
与top (1) with ties
使用,并带有可用于 SQL 服务器(最初被标记)的关系:
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;
相关子查询是一种简单的方法:
select t.*
from t
where t.update_date = (select max(t2.update_date) from t t2 where t2.number = t.num);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.