3

我想从mysql查询的四个字段中搜索最小值,我尝试了很多方法但没有得到它,现在我只从一个字段中搜索,

这是我的领域。

表:包

package_id        price   price_double    price_triple    price_quad

我想从四个字段中搜索最小金额

就像在 php 函数中一样

 min(price,price_double,price_triple,price_quad).

但我想在 mysql 查询中实现它,这怎么可能?请帮我。提前致谢。

4

3 回答 3

4

使用最少

SELECT
    package_id,
    LEAST(price, price_double, price_triple, price_quad) AS price
FROM package;
于 2013-05-02T06:36:47.273 回答
0
select     case when price <= price_double and price <= price_triple and price<=price_quad then price
           when price_double <= price and price_double <= price_triple and price_double <=price_quad then price_double
          when price_triple<=price and price_triple<=price_double and pricetriple <= price_quad then price_triple
           when price_quad <= price and price_quad <= price_double and price_quad <=price_triple then price_quad
    end as 'TheMin'             

from Table packages

如果您有任何疑问,请查看此stackoverflow问题链接。

于 2013-05-02T06:11:05.557 回答
0

你怎么看?这样对吗?

   SELECT LEAST(MIN(price), MIN(price_double), MIN(price_triple), MIN(price_quad))
   AS MinOfAllColumns
   FROM packages
于 2013-05-02T06:15:59.477 回答