SQL MAX of multiple columns?

后端 未结 22 1859
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 02:03

How do you return 1 value per row of the max of several columns:

TableName

[Number, Date1, Date2, Date3, Cost]

I n

22条回答
  •  死守一世寂寞
    2020-11-22 02:25

    Another way to use CASE WHEN

    SELECT CASE true 
           WHEN max(row1) >= max(row2) THEN CASE true WHEN max(row1) >= max(row3) THEN max(row1) ELSE max(row3) end ELSE
           CASE true WHEN max(row2) >= max(row3) THEN max(row2) ELSE max(row3) END END
    FROM yourTable
    

提交回复
热议问题