![](/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.