注册 登录
编程论坛 SQL Server论坛

求多列中的最小值

timeyh 发布于 2012-12-24 23:13, 595 次点击
ID      price1   price2  price3
19415    61       90      90
03892    60       72      85
05749    60       120     190
06166    60       178     394
06447    60       124     224
07740    60       156     276
07836    60       83      88
09728    60       133     227
03018    59       113     157
05175    58       63      85
我需要通过查询各ID的所对应的price最小的值。select id,min(price1,price2,price3) from table 报错。应该怎么写?
2 回复
#2
半杯清茶2012-12-25 09:25
select [ID],
       [MINIPrice]=(select min([price1])
              from (select [price1]
                  union all select [price2]
                  union all select [price3]
                  union all select [price4])T)
from table
#3
dqk9112015-01-07 16:36
这个答案,高手能解释下吗,什么原理
1