sql怎么查询一个列的最大值?
方法一SELECTID,Name,(SELECTMAX(LastUpdateDate)FROM(VALUES(UpdateByApp1Date),(UpdateByApp2Date),(UpdateByApp3Date))ASUpdateDate(LastUpdateDate))ASLastUpdateDateFROM##TestTable方法二SELECTID,[Name],MAX(UpdateDate)ASLastUpdateDateFROM##TestTableUNPIVOT(UpdateDateFORDateValIN(UpdateByApp1Date,UpdateByApp2Date,UpdateByApp3Date)
)ASuGROUPBYID,Name方法三SELECTID,name,(SELECTMAX(UpdateDate)ASLastUpdateDateFROM(SELECTtt.UpdateByApp1DateASUpdateDateUNIONSELECTtt.UpdateByApp2DateUNIONSELECTtt.UpdateByApp3Date)ud)LastUpdateDateFROM##TestTablett