在请教一下,我的代码是这样的 select ...,(b.quantity-isnull(SUM(c.quantity),0))*b.unit_price as item_amount from ...我想要最终得出的结果 item_amount 如果为负数为显示0,这个应该怎么写呀?
我写成了 select ...,case when ((b.quantity-isnull(SUM(c.quantity),0))*b.unit_price) <0 then 0 else (b.quantity-isnull(SUM(c.quantity),0))*b.unit_price end as item_amount from ...发现没有起什么作用,况且,这样是不是要重复统计计算两次影响效率呀?应该怎么写呀?
case when col < 0 then 0 else col end
select ...,(b.quantity-isnull(SUM(c.quantity),0))*b.unit_price as item_amount from ...我想要最终得出的结果 item_amount 如果为负数为显示0,这个应该怎么写呀?
select ...,case when ((b.quantity-isnull(SUM(c.quantity),0))*b.unit_price) <0 then 0 else (b.quantity-isnull(SUM(c.quantity),0))*b.unit_price end as item_amount from ...发现没有起什么作用,况且,这样是不是要重复统计计算两次影响效率呀?应该怎么写呀?