As your query will give the right results ,but you mention only one single data, quantity in your query .
That is because you did not provide any sample data yourself. If you want a fully tested query, the recommendation is that you provide the CREATE TABLE statements for your query and INSERT statements with sample data. We also need the expected result given the sample. Then we can easily copy this into a query window to develop a tested solution. Without that we may work with a simpler table like Echo did, or just give you an outline of the query like I did.
You don't seemed to have tried my solution. I thought it would be a very good fit given your original post, but when I read your comment I get less that I understand what you are looking for.