On Wed, Jan 7, 2009 at 1:48 PM, Jerry Schwartz
wrote:
>
>
>>-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:
>-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
On Tue, Jan 6, 2009 at 3:13 PM, Jerry Schwartz
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-the-firstleastmax-row-per-group-in-sql/
Keep reading, it ta
] 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 (
>-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
>
>
How about something like
select account,customer,max(total) from (select
account,customer,sum(sale_amount) as total from 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
wrote:
> Here's a bit of business t