Re: Limit within groups

2009-01-07 Thread Baron Schwartz
On Tue, Jan 6, 2009 at 3:13 PM, Jerry Schwartz jschwa...@the-infoshop.com wrote: Each account has multiple customers, and each customer has multiple sales. I want to get the top 20 customers for each account.

RE: Limit within groups

2009-01-07 Thread Jerry Schwartz
-Original Message- From: baron.schwa...@gmail.com [mailto:baron.schwa...@gmail.com] On Behalf Of Baron Schwartz Sent: Wednesday, January 07, 2009 9:54 AM To: Jerry Schwartz Cc: mysql@lists.mysql.com Subject: Re: Limit within groups On Tue, Jan 6, 2009 at 3:13 PM, Jerry Schwartz jschwa

Re: Limit within groups

2009-01-07 Thread Baron Schwartz
: Re: Limit within groups On Tue, Jan 6, 2009 at 3:13 PM, Jerry Schwartz jschwa...@the-infoshop.com wrote: Each account has multiple customers, and each customer has multiple sales. I want to get the top 20 customers for each account. http://www.xaprb.com/blog/2006/12/07/how-to-select

Re: Limit within groups

2009-01-06 Thread Phil
How about something like select account,customer,max(total) from (select account,customer,sum(sale_amount) as total from tablename group by customer) as y group by account; Seems to work in my test case.. Regards Phil On Tue, Jan 6, 2009 at 3:13 PM, Jerry Schwartz

RE: Limit within groups

2009-01-06 Thread Jerry Schwartz
-Original Message- From: freedc@gmail.com [mailto:freedc@gmail.com] On Behalf Of Phil Sent: Tuesday, January 06, 2009 3:41 PM To: Jerry Schwartz Cc: mysql@lists.mysql.com Subject: Re: Limit within groups How about something like select account,customer,max(total) from (select

Re: Limit within groups

2009-01-06 Thread Phil
: Tuesday, January 06, 2009 3:41 PM To: Jerry Schwartz Cc: mysql@lists.mysql.com Subject: Re: Limit within groups How about something like select account,customer,max(total) from (select account,customer,sum(sale_amount) as total from tablename group by customer) as y group by account