Use row_number()
with top (1) with ties
available for SQL Server (which was initially tagged):
select top (1) with ties t.*
from table t
order by row_number() over (partition by no order by date desc);
You can also use subquery:
select t.*
from (select t.*, row_number() over (partition by no order by date desc) as seq
from table t
) t
where seq = 1;
A correlated subquery is a simple method:
select t.*
from t
where t.update_date = (select max(t2.update_date) from t t2 where t2.number = t.num);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.