[英]How to get the Exact Batch ID from stock table on the basis of Expiry Date?
我想根據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
您正在使用匯總最小函數,它會給您錯誤的輸出。您可以使用按函數排序以進行排序。
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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.