I’m trying to do a query where it adds up the totals for the orders from each customer.
I have tried a few different ways but I am not sure the right way to do it.
I’ve tried…
SELECT *
FROM Orders
SUM(Total) as Totals
COUNT(OrderID) as OrderAmt
GROUP BY CustomerID, OrderAmt, ShipName, Totals
I want to get this result….
=====================================
|CustomerID|Orders |ShipName|Total |
|==========|=======|========|=======|
|3334 |3 |Joe Blow|1100.00|
|----------|-------|--------|-------|
|114 |2 |Steve |280.00 |
|----------|-------|--------|-------|
|1221 |1 |Sue |250.00 |
|----------|-------|--------|-------|
|3444 |1 |Bob |22.00 |
=====================================
From this table…
|===================================|
|CustomerID|OrderID|ShipName|Total |
|==========|=======|========|=======|
|3334 |232 |Joe Blow|400.00 |
|----------|-------|--------|-------|
|3334 |234 |Joe Blow|500.00 |
|----------|-------|--------|-------|
|3334 |231 |Joe Blow|200.00 |
|----------|-------|--------|-------|
|114 |235 |Steve |250.00 |
|----------|-------|--------|-------|
|114 |239 |Steve |30.00 |
|----------|-------|--------|-------|
|1221 |244 |Sue |250.00 |
|----------|-------|--------|-------|
|3444 |632 |Bob |22.00 |
|===================================|
What would be the correct SQL statement for this.
Sumandcountcan be used to get the result you want: