I have a subquery where I am sorting first by ProductNumber and then by DateStamp.
I want to find the last quantity of each product on a given date (the quantity changes throughout the day). My query currently groups by ProductNumber, looks for Max DateStamp, and Last Quantity. But it is not working properly. The Quantity never seems to be the actual last quantity, but something in the middle somewhere, even though I can see that the subquery is sorting properly, and it is correctly finding Max of DateStamp.
Is there some way to pull the Quantity from the same record as the Max DateStamp is read from?
Thanks!
I want to find the last quantity of each product on a given date (the quantity changes throughout the day). My query currently groups by ProductNumber, looks for Max DateStamp, and Last Quantity. But it is not working properly. The Quantity never seems to be the actual last quantity, but something in the middle somewhere, even though I can see that the subquery is sorting properly, and it is correctly finding Max of DateStamp.
Is there some way to pull the Quantity from the same record as the Max DateStamp is read from?
Thanks!
Comment