此查询工作正常
SELECT `category`
, `product`
, `(SUM(CASE WHEN stock.is_out = false and stocktrxn.is_defective = false
THEN qty
ELSE 0 END)
- SUM(CASE WHEN stock.is_out = true
THEN qty
ELSE 0 END))` AS `qty_available`
, `(SUM(CASE WHEN stock.is_out = false a`nd stocktrxn.is_defective = true THEN qty ELSE 0 END))` AS `qty_defective`
, `(SUM(CASE WHEN stock.is_out = false THEN qty ELSE 0 END) - SUM(CASE WHEN stock.is_out = true THEN qty ELSE 0 END))` AS `qty_sum`
FROM `product`
LEFT JOIN `stocktrxn`
ON `product`.`id` = `stocktrxn`.`product_no`
LEFT JOIN `stock`
ON `stock`.`tra_no` = `stocktrxn`.`tra_no `
GROUP BY `stock`.`warehouse_id`, `product`
ORDER BY `category`, `product_name`, `product_type`, `dqty1`, `dqty2`
但是一旦我添加了stock
。warehouse_id
= :warehouse_id
我最终得到的产品没有省略交易。
添加where的正确方法是什么?