Retrieve data based on sum of rows group by product - SQL, SSMS

My data comprises of "Stock Qty" and would like to know what the qty recieved was and the purchased price was based on the latest purchase orders - only up to the qty currently available.
I am able to do this to and created a new calculated column called "Stock Qty New".

So in my attached example, I would now like to filter to show on the rows where the sum of "Stock Qty New" is <= to "Stock Qty" by ProductId.
("Stock Qty" is correctly repeating and shown validating purposes).

So for ProductId AA08510, I would want to see row number 1 only as the first Purchase Order has the 13 items which make the current stock.
For ProductId DZ51855, I would want to see row numbers 4,5 only as both Purchase Orders have 145 items (100 + 45) which make the current stock.
For ProductId FC03201, I would want to see row numbers 6,7 only as both Purchase Orders have 4 items (3 + 1) which make the current stock.



Any suggestions much appreciated and let me know if further information required.
Thanks in advance.
Stock.docx
Bhagat SBusiness Intelligence AnalystAsked:
Who is Participating?
 
Pawan KumarConnect With a Mentor Database ExpertCommented:
I think you just need this. Please try

Select * from yourTable
WHERE  [Stock Qty New]  > 0
0
 
Bhagat SBusiness Intelligence AnalystAuthor Commented:
Yes, this works fine.
Many thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.