ASP Hosting sale!
Double disk space and transfer for FREE!
Limited time offer! Act Now!

aspdev | articles | tutorials | forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SQL Question - Select customers with more than 3 orders...

 
Post new topic   Reply to topic    ASPdev.org Forum Index -> SQL Programming (MS SQL Server, MS Access, MySQL)
View previous topic :: View next topic  
Author Message
ska



Joined: 13 Dec 2004
Posts: 1

PostPosted: Mon Dec 13, 2004 10:21 am    Post subject: SQL Question - Select customers with more than 3 orders... Reply with quote

Hi,

I have a table called ORDERS in a SQL Server 2000 database and I need to get a list of all the customers with more than 3 orders. Here is my ORDERS table structure:

OrderID INT PK
CustomerID INT
OrderDate DATETIME
OrderAmount FLOAT

Do you know how to select all customers (CustomerID) appearing more than 3 times in the ORDERS table?



Thanks
_________________
Ska Forever :/
Back to top
View user's profile Send private message
paul



Joined: 11 Oct 2004
Posts: 128

PostPosted: Mon Dec 13, 2004 11:45 am    Post subject: Reply with quote

You'll have to use the SQL HAVING command to do that, like this:

Code:

SELECT CustomerID, COUNT(CustomerID) FROM ORDERS
GROUP BY CustomerID
HAVING COUNT(CustomerID) > 3



Read more about the SQL HAVING statement here:

http://www.sql-tutorial.net/SQL-HAVING.asp
_________________
World Countries | Survival Skills
Back to top
View user's profile Send private message
x-raysteve



Joined: 01 Feb 2006
Posts: 53

PostPosted: Wed Feb 01, 2006 7:10 pm    Post subject: Reply with quote

Learn something new the other day. I had something I was trying to debug the other day and this would have come in helpful. I never even heard of the having command before.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ASPdev.org Forum Index -> SQL Programming (MS SQL Server, MS Access, MySQL) All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group

SQL Tutorial