Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
order by sum(amount) desc
Old
  (#1)
PeterD
Guest
 
Posts: n/a
Default order by sum(amount) desc - 06-04-2007, 07:58 AM

I have a table of transactions, with a Who field. I want a list of all
the distinct Who values, a total of their transactions, starting from
the biggest total.

Why doesn't this work?

select who, sum(amount)
from transactions
group by who
order by sum(amount) desc

--
Pd
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: order by sum(amount) desc
Old
  (#2)
PeterD
Guest
 
Posts: n/a
Default Re: order by sum(amount) desc - 06-04-2007, 07:58 AM

PeterD <EMAIL REMOVED> wrote:

> I have a table of transactions, with a Who field. I want a list of all
> the distinct Who values, a total of their transactions, starting from
> the biggest total.
>
> Why doesn't this work?
>
> select who, sum(amount)
> from transactions
> group by who
> order by sum(amount) desc


Oops, never mind. This works:

select who, sum(amount) Total
from transactions
group by who
order by Total desc

--
Pd
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top