Get the minimum value between several columns

后端 未结 4 570
遇见更好的自我
遇见更好的自我 2020-12-20 19:35

I\'m using SQL Server 2008;

Suppose I have a table \'X\' with columns \'Date1\', \'Date2\', \'Dateblah\', all of type DateTime.

I want to select the min valu

4条回答
  •  醉酒成梦
    2020-12-20 19:53

    Simply lets say the table where your dates are is called sells and it has two date fields Date1 and Date2 from which you want the minimum.

    SELECT ( 
       SELECT MIN([x]) 
       FROM (VALUES(Date1),(Date2)) x([x])
    ) as minimum
    FROM sells
    

提交回复
热议问题