Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Sum

Author  Topic 

Knarf180
Starting Member

42 Posts

Posted - 2004-11-19 : 11:30:04
I'm sure there is an easy way to do something like this but its just not hitting me today. Basically I have a bunch of records linked by a customer number. I need to find the number of customers whos total purchases are greater then $2000.

Sample table:
CustomerID orderNumber ItemNumber Cost
1000 500 3334 3.45
1000 500 4324 5.22
1001 501 2332 4.43
1001 501 3494 8.99


Basically it must be grouped by customer number and the sum of the cost must greater then 2000. I'm tired and its Friday.. Any advice?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-11-19 : 11:34:09
SELECT CustomerID, Sum(Cost) AS Total FROM myTable GROUP BY CustomerID HAVING Sum(Cost)>2000
Go to Top of Page

Knarf180
Starting Member

42 Posts

Posted - 2004-11-19 : 11:40:13
Ahh, I love this board. Thanks much.
Go to Top of Page
   

- Advertisement -