Compare values of two columns then select the larger value

前端 未结 6 652
孤街浪徒
孤街浪徒 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 11:37

    Try this code:

    SELECT column1, column2,
           (CASE WHEN column3 > column4 THEN column3 ELSE column4 END)
      FROM Table1
    

    Result:

    COLUMN1   COLUMN2  Hybrid
     hello     hello      5
      hi         hi       7
    

    Here you have complete sample on SQL Fiddle.

提交回复
热议问题