select sum(if(qty > 0, qty, 0)) as total_qty from inventory_product group by product_id
意思是如果qty > 0, 将qty的值累加到total_qty, 否则将0累加到total_qty.
sum( if( qty < 0, 1, 0 )) as negative_qty_count
判断qty的值 如果小于0 则将 negative_qty_count的值+1,否则+0
select sum(if(qty > 0, qty, 0)) as total_qty from inventory_product group by product_id
意思是如果qty > 0, 将qty的值累加到total_qty, 否则将0累加到total_qty.
sum( if( qty < 0, 1, 0 )) as negative_qty_count
判断qty的值 如果小于0 则将 negative_qty_count的值+1,否则+0