Compare values of two columns then select the larger value

前端 未结 6 701
孤街浪徒
孤街浪徒 2021-02-12 11:30

I need to query a table and select 3 of the values of 4 columns. I need to compare the values of the 3rd column and the fourth column and select the larger value.

For ex

6条回答
  •  遥遥无期
    2021-02-12 12:01

    You can use CASE, but if one of the values is 'null', the 'null' is considered the greatest value.

    To solve this problem you can use GREATEST

    SELECT GREATEST(column3, column4)
    FROM Table1
    

提交回复
热议问题