Wednesday 20 May 2015

MSSQL - Min funciton that takes 2 or more values - like Math.Min in .NET

Watch this example on YouTube:


Here is my table


The following query will get minimum bonus, salary or gambling for each customer, whichever is the lowest:

Select CustomerName,
  (Select Min(Amount)
   From (Values (Bonus), (Salary), (Gambling)) as tblMinimum(Amount))
From Table3

Here is my output:





No comments:

Post a Comment