Compare values of two columns then select the larger value

前端 未结 6 1268
挽巷
挽巷 2021-02-12 11:03

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:41

    In T-SQL the IF command is for programatic control. For example:

    • IF x THEN doSQLStatement1 ELSE doSQLStatement2


    Within a SQL statement, you need CASE.

    CASE WHEN a > b THEN a ELSE b END
    

提交回复
热议问题