表格价格
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
如何从价格中选择最低价格WHERE user_id ='MP01'?
user_id MP01的示例,以获得结果12
答案 0 :(得分:2)
根据你的例子,我认为你的意思是结果是12.如果是这样你可以做
SELECT LEAST(b01, b02, b03, b04, b05, b06, b07, b08, b09) FROM price WHERE user_id = 'MP01'
答案 1 :(得分:1)
这是LEAST的替代方法。使用最少功能并不容易。但在某些情况下可能派上用场
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'
答案 2 :(得分:0)
您可以使用least
select least(b01,b02,b03,b04,b05,b06,b07,b08,b09)
FROM Table1
where user_id='MP01'
答案 3 :(得分:0)
您可以使用LEAST功能,如:
select least(b01,b02,b03,b04,b05,b06,b07,b08,b09) from price where user_id = 'MP01'
http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_least