Query to find the sum of fields...

H

Hendy88

Hello all,

I have an orders table that stores all the orders from various
customers sorted by order date descending (I guess that part doesn't
really make a difference). Anyhow, I want a query that gives me a
"grand total" of every order from a particular customer. I'm really
not sure how to go about it... with a Select Query or CrossTab Query
or even a different way completely.

What I have is a table called [ORDERS] with the following fields:

OrderID
OrderDate
CustomerID
OrderTotal
etc.

Obviously there are orders placed from the same customer throughout
the year but would have different "OrderID"s, "OrderDate"s,
"OrderTotal"s, and whatnot throughout the whole table.

What I need is a query that gives me a "total-of-totals". So even
though John Smith (Customer ID = 2323345), had two orders in January
and another in February and so on... I want a Grand Total persay of
every order. Right now all I can come up with is just a Select Query
which shows me:

07235552-12 1/3/07 2323345 $47.65
07283456-14 1/23/07 2323345 $64.43
07462312-11 2/25/07 2323345 $23.18

What I really need is just the following:

2323345 $135.26

But not only for John Smith, but for all customers. Any help would
greatly be appreciated on how to accomplish this.

Thanks in advance!
 
M

Marco Pagliero

Hello all,

I have an orders table that stores all the orders from various
customers sorted by order date descending (I guess that part doesn't
really make a difference). Anyhow, I want a query that gives me a
"grand total" of every order from a particular customer. I'm really
not sure how to go about it... with a Select Query or CrossTab Query
or even a different way completely.

What I have is a table called [ORDERS] with the following fields:

OrderID
OrderDate
CustomerID
OrderTotal
etc.

Obviously there are orders placed from the same customer throughout
the year but would have different "OrderID"s, "OrderDate"s,
"OrderTotal"s, and whatnot throughout the whole table.

What I need is a query that gives me a "total-of-totals". So even
though John Smith (Customer ID = 2323345), had two orders in January
and another in February and so on... I want a Grand Total persay of
every order. Right now all I can come up with is just a Select Query
which shows me:

07235552-12 1/3/07 2323345 $47.65
07283456-14 1/23/07 2323345 $64.43
07462312-11 2/25/07 2323345 $23.18

What I really need is just the following:

2323345 $135.26

But not only for John Smith, but for all customers. Any help would
greatly be appreciated on how to accomplish this.

SELECT CustomerID, SUM(OrderTotal) from Orders GROUP BY CustomerID ;

Greetings
Marco P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top