We have a storage system that is full. I am trying to identify items currently in the storage system that are 'inactive' (have not been moved in a long time). With this I would have an easy way of identifying which items I can remove from the system to free up those locations for active items. I want a query that will show me the date of the last movement for each item (one result per unique item). Does that make sense?
I have 2 tables, that will need to be joined using item_id.
movement_log:
item_id time operation container quantity
A 2020-01-01 11:00:00.000 Load 1 90
B 2020-01-01 13:00:00.000 Load 2 30
C 2020-01-02 09:00:00.000 Load 3 10
D 2020-01-03 15:00:00.000 Load 4 7
E 2020-01-03 15:30:00.000 Load 6 220
A 2020-01-03 16:00:00.000 Load 5 20
B 2020-01-03 17:00:00.000 Unload 2 10
C 2020-01-04 09:00:00.000 Load 3 5
D 2020-01-05 11:00:00.000 Unload 4 2
D 2020-01-06 11:00:00.000 Unload 4 2
B 2020-01-06 12:00:00.000 Unload 2 10
A 2020-01-06 13:00:00.000 Unload 1 10
E 2020-01-06 14:00:00.000 Unload 6 220
current_item_positions:
item_id container quantity
A 1 80
B 2 10
C 3 15
D 4 3
A 5 20
C 3 15
Query Result:
item_id last_movement last_operation
C 2020-01-04 09:00:00.000 Load
D 2020-01-06 11:00:00.000 Unload
B 2020-01-06 12:00:00.000 Unload
A 2020-01-06 13:00:00.000 Unload
Any ideas for how to achieve this?