[英]How to search min value from four other different fields in mysql query?
I want to search min value from four fields in mysql query, I have tried a lot of ways but didn't get it, right now I am searching only from one field, 我想从mysql查询中的四个字段中搜索min值,我已经尝试了很多方法但是没有得到它,现在我只在一个字段中搜索,
here are my fields. 这是我的领域。
Table :packages 表:包
package_id price price_double price_triple price_quad
I want to search the min amount from four fields 我想从四个字段中搜索最小量
like in php function 喜欢在php函数中
min(price,price_double,price_triple,price_quad).
but I want to implement it in mysql query how can this be possible? 但是我想在mysql查询中实现它怎么可能呢? please help me. 请帮我。 thanks in advance. 提前致谢。
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
If you have any doubt please check this stackoverflow question link. 如果您有任何疑问,请查看此stackoverflow问题链接。
what you think about that? 你怎么想的? is it right? 这样对吗?
SELECT LEAST(MIN(price), MIN(price_double), MIN(price_triple), MIN(price_quad))
AS MinOfAllColumns
FROM packages
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.