我的目标是为我们的库存系统创建一份报告,以显示我们是 IN 库存还是 OUT 的产品库存A B& C.我们的股票分为两列,分别为physical_qty
和allocated_qty
使用此查询,我可以从physical_qty
中减去allocated_qty
并将其显示为stock
SELECT
warehouse, product, description, physical_qty - allocated_qty AS stock
FROM
scheme.stockm
WHERE
(warehouse = '01') AND (product IN ('A', 'B', 'C'))
这给了我们可以出售的股票数量的数值。
我如何评估库存是否为< 1显示 OUT ,否则显示 IN ?
由于
答案 0 :(得分:2)
像这样:
SELECT warehouse, product, description,
physical_qty - allocated_qty AS stock,
CASE WHEN (physical_qty - allocated_qty) < 1 THEN 'OUT'
ELSE 'IN' END AS Stock_Status
FROM scheme.stockm
WHERE (warehouse = '01') AND (product IN ('A', 'B', 'C'))
答案 1 :(得分:0)
尝试
CASE WHEN physical_qty - allocated_qt < 1 THEN 'OUT' ELSE 'IN' END