2014-10-27 264 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'