答案 0 :(得分:0)
尝试这种方式:
select
Database ,
Servername,
max(dateadded)
from table_db
group by Database ,Servername
答案 1 :(得分:0)
试试这个:
select serverName,
InstanceName,
DBName,
RecoveryModel,
DateAdded,
LastBackupDate,
LastDifferentialBackupDate,
LastLogBackupDate
from (
select serverName,
InstanceName,
DBName,
RecoveryModel,
DateAdded,
LastBackupDate,
LastDifferentialBackupDate,
LastLogBackupDate,
row_number() over(partition by serverName,DBname order by DateAdded desc) as rn
from DB.databaseinfo
) X
where X.rn=1
order by X.serverName,X.InstanceName,DBName
答案 2 :(得分:-1)
select *
from (select *
,row_number ( ) over
(
partition by Servername,InstanceName,DBName
order by DateAdded desc
) as rn
from MyTable
) t
where rn = 1
;