我想根据 fifo 到期日期从库存表中获取批处理 ID。如何得到它。我编写了一个查询,它给出了确切的批处理,但批处理 ID 不准确。基本上我想获取第一个过期产品的批处理
股票表就像这样
Batch_ID | Product_ID | Quantity | Is_Expiry |Expiry_Date | Location_ID
6 | 148 | 90 | 1 | 2019-08-24 | 1
4 | 148 | 75 | 1 | 2019-09-13 | 1
2 | 148 | 0 | 1 | 2019-07-11 | 1
我写这个查询
Select batch_id,min(datediff(expiry_date,now())) as Remaining_Days From Stock Where Product_ID = '148' and quantity > 0 and Location_ID = '1'
电流输出
Batch_ID | Remaining_Days
4 | 56
预期输出:
Batch_ID | Remaining_Days
6 | 56
最佳答案
您正在使用聚合 min 函数,它会给出错误的输出。您可以使用 order by 函数进行排序。
Select batch_id,(datediff(expiry_date,now())) as Remaining_Days From stock
Where Product_ID = '148' and quantity > 0 and Location_ID = '1'
order by Remaining_days
limit 1;
关于c# - 如何根据到期日期从库存表中获取准确的批处理 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56813147/