请高手帮忙看下, 如何一句 MySQL 语句查询库存
请教各位高手
stock_type:
in: 进货
in_return: 进货后退货 (amount要转为负值)
out: 销货 (amount要转为负值)
out_return: 销货后退货
adjust: 手动调整库存
transfer: 货物转仓 (out_warehouse_id 转出仓库id, in_warehouse_id 转入仓库id)
例如: id: 42 => 产品id:19 => 1号仓 -30 / 2号仓 +30
select sum( IF(stock_type = 'out' or stock_type = 'in_return', -1 * amount, amount)) as stock_total
from stock_items where stock_type != 'transfer'
group by warehouse_id, product_id
写到这里就卡住了 transfer 的条件不知道该如何加入语句中
想请教高手们 如何一句SQL 求 各仓库的各产品库存?
感谢!
为何要用mysql做这些事?可以在项目代码层面做这些事呀