SQL语句取多列的最小值(排除0)

经常遇到获取数据表中多个列的最小值和最大值,例如:

 

获取这 4个价格的最小值和最大值:

SELECT
(
SELECT min(minPrice)
FROM
(
VALUES
(IIF(MarketSingleImagetextPrice=0,null,MarketSingleImagetextPrice)),
(IIF(MarketMoreGraphicOnePrice=0,null,MarketMoreGraphicOnePrice)),
(IIF(MarketMoreGraphicTwoPrice=0,null,MarketMoreGraphicTwoPrice)),
(IIF(MarketMoreGraphicThreePrice=0,null,MarketMoreGraphicThreePrice))
) AS #temp(minPrice)
) AS MinIboPrice
FROM YX_WeChatFlowMode WHERE ShapeID=1 AND FlowID = 1656

 

 

posted on 2018-04-03 16:18 763595696 阅读() 评论() 编辑 收藏

版权声明:本文为51lazy原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/51lazy/p/8709174.html