I have a trx table that records issues and receipts into a bin. I'm trying to find a way to find the bin that has a qty with the oldest receipt date.
Data will look like this: R = Receipt I = Issue tablename: QIVBinTrx
item_no Bin_no Qty date doc_type
BTEST BINA 20 2015-07-01 R
BTEST BINA 6 2015-07-02 I
BTEST BINA 14 2015-07-03 I
BTEST BINA 10 2015-07-04 R
BTEST BINA 5 2015-07-05 R
What I'm looking for is the last receipt date that filled this bin.
The Bin was fully issued on 07/03/2015 which brought it to zero.
Then a receipt was done the next day for 10. I need to know the last receipt date in that bin was 07/04/2015
Then if it get zeroed again I would need it to find the next receipt date that started to fill it again.
What I would like returned is:
Item BIN QTY Last Receipt Date
BTEST BINA 15 2014-07-04
I know I can get the qty by
select item_no, bin_no, SUM(qty) as BinQty
from QIVBinTrx
group by item_no, bin_no
Not sure if there is a way to get the date I want.