SQL MAX of multiple columns?

后端 未结 22 1820
伪装坚强ぢ
伪装坚强ぢ 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:23

    Above table is an employee salary table with salary1,salary2,salary3,salary4 as columns.Query below will return the max value out of four columns

    select  
     (select Max(salval) from( values (max(salary1)),(max(salary2)),(max(salary3)),(max(Salary4)))alias(salval)) as largest_val
     from EmployeeSalary
    

    Running above query will give output as largest_val(10001)

    Logic of above query is as below:

    select Max(salvalue) from(values (10001),(5098),(6070),(7500))alias(salvalue)
    

    output will be 10001

提交回复
热议问题