OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
Limit within groups

From: Jerry Schwartz (jschwartzthe-infoshop.com)
Date: Tue Jan 06 2009 - 14:13:08 CST


Here's a bit of business that is baffling me, and probably shouldn't. My
table looks like this:

 

account

customer

sale_amount

 

Each account has multiple customers, and each customer has multiple sales. I
want to get the top 20 customers for each account.

 

If I simply do "GROUP BY account, customer LIMIT 20", I'll get the first 20
customers for the first account. If I try "GROUP BY account, customer ORDER
BY SUM(sale_amount) DESC LIMIT 20", I'll get the top 20 customers.

 

What am I missing?

 

Regards,

 

Jerry Schwartz

The Infoshop by Global Information Incorporated

195 Farmington Ave.

Farmington, CT 06032

 

860.674.8796 / FAX: 860.674.8341

 

 <http://www.the-infoshop.com> www.the-infoshop.com

 <http://www.giiexpress.com> www.giiexpress.com

www.etudes-marche.com