1

I have a table of order information called Demands with data that would look something like this:

Invoice | Product | Quantity | Route
————————|—————————|——————————|——————————
2254619 | A       | 10       | 20160112
2254619 | B       | 5        | 20160112
2254619 | C       | 4        | 20160112
2254619 | D       | 7        | 20160112
2254619 | E       | 3        | 20160112
2254808 | A       | 8        | 20160112
2254808 | B       | 2        | 20160112
2254808 | C       | 9        | 20160112
2254808 | D       | 0        | 20160112
2254808 | E       | 11       | 20160112
2254902 | A       | 7        | 20160113
2254905 | A       | 4        | 20160113

What I need is a query that will calculate the total Quantity for ALL Products for every Route.

So, the results would show that Route 20160112 has a Quantity of 18 of Product A, 7 of Product B, etc. and that Route 20160113 has 11 Product A, etc.

And this will be for multiple routes and many different products.

Any help you guys can provide would be immensely appreciated.

2 Answers 2

4

Group rows and use aggregate functions

SELECT Route, Product, SUM(Quantity)
FROM   Demands
GROUP BY Route, Product
Sign up to request clarification or add additional context in comments.

1 Comment

That did it. Thank you!
0

Oops, I missed the previous post that obviously is exactly the same as mine.

Wouldn't "GROUP BY" work?

SELECT Product, Route, SUM(Quantity) FROM table GROUP BY Product, Route;

SUM() applies to records of a "group" defined by Product and Route.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.