方法一
SELECT ID ,
Name ,
( SELECT MAX(LastUpdateDate)
FROM ( VALUES ( UpdateByApp1Date), ( UpdateByApp2Date),
( UpdateByApp3Date) ) AS UpdateDate ( LastUpdateDate )
) AS LastUpdateDate
FROM ##TestTable
方法二
SELECT ID ,
[Name] ,
MAX(UpdateDate) AS LastUpdateDate
FROM ##TestTable UNPIVOT ( UpdateDate FOR DateVal IN ( UpdateByApp1Date,
UpdateByApp2Date,
UpdateByApp3Date ) ) AS u
GROUP BY ID ,
Name
方法三
SELECT ID ,
name ,
( SELECT MAX(UpdateDate) AS LastUpdateDate
FROM ( SELECT tt.UpdateByApp1Date AS UpdateDate
UNION
SELECT tt.UpdateByApp2Date
UNION
SELECT tt.UpdateByApp3Date
) ud
) LastUpdateDate
FROM ##TestTable tt
select max(column) from tablename