2014-10-27 165 views
1

表价格MySQL的选择多选择

user_id b01 b02 b03 b04 b05 b06 b07 b08 b09 
MP01  21  32  12  34  56  26  21  21  26  
MO11  81  332 112 1  12  22  71  17  23 

最低价如何选择最低价格从价格其中USER_ID =“MP01”?

例如为USER_ID MP01,得到的结果在你的榜样12

+1

应该不是最低的价格是12? – 2014-10-27 03:38:12

回答

2

基地我想你所指的结果是12。如果这是你可以做的

SELECT LEAST(b01, b02, b03, b04, b05, b06, b07, b08, b09) FROM price WHERE user_id = 'MP01' 
0

可以使用least的情况下

select least(b01,b02,b03,b04,b05,b06,b07,b08,b09) 
FROM Table1 
where user_id='MP01' 
1

这是一种替代方法,以最少。使用最少的功能并不容易。但在某些情况下可能派上用场

SELECT MIN(b01) FROM(
select user_id , b01 from price 
union all 
select user_id , b02 from price 
union all 
select user_id , b03 from price 
union all 
select user_id , b04 from price 
union all 
select user_id , b05 from price 
union all 
select user_id , b06 from price 
union all 
select user_id , b07 from price 
union all 
select user_id , b08 from price 
union all 
select user_id , b09 from price 
) temp 
WHERE user_id = 'MP01'