How to using IF statement in WHERE? Below code doesn't works
SELECT item.item_id,
item.item_name,
item.item_qty
IF(sell.product_qty IS NULL, item.item_qty, item.item_qty - SUM(sell.product_qty)),
sell.date_order,
sell.date_shipping
FROM item
OUTER JOIN sell
ON item.item_id = sell.product_item_id
WHERE NOW() BETWEEN sell.date_order AND sell.date_shipping
You should use CASE statement.
CASE WHEN sell.product_qty IS NULL THEN item.item_qty
ELSE item.item_qty - SUM(sell.product_qty) END
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.