SQL Selecting MIN value from row data, not column data
问题 Using SQL 2005, is there a way to select the minimum value between 5 columns within one single row of data? So, if I have a row of data like this: id num1 num2 num3 num4 num5 1 22 51 4 99 34 Then, how can I get the lowest value using SQL? 回答1: You can create a UDF. create function GetMin(@N1 int, @N2 int, @N3 int, @N4 int, @N5 int) returns table as return (select min(N) as Value from (select @N1 union all select @N2 union all select @N3 union all select @N4 union all select @N5) as T(N)) And