Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting on sums

Status
Not open for further replies.

HomerJS

Programmer
Jun 25, 2001
86
US
I'm trying to list the top customers by an amount field. I need to calculate the amount field before I can sort it. I can total up the amount field. The problem I'm having is figuring out a way to sort by the totaled amount.

I am doing this in a web page (using InterDev) so I need something that can have values passed to it so I can select records by a certain date range, etc.

example . . .
Table:
Cust# Amt
1 10.00
2 7.50
2 20.00
1 9.50

Result desired:
Cust# Amt
2 27.50
1 19.50

If this is clear as mud let me know and I will try to explain more.

 
[tt]select CustNum, sum(amt) as Amount
from MyTable
group by CustNum
order by sum(amt) desc [/tt]
Robert Bradley
Sr. DBA, some big company
cheap prints and oil paintings:
 
Ok, that worked great. Now how do I use that sum value inside of InterDev? InterDev doesn't like the use of "sum(Amt)".
 
I'm not an InterDev user, but the result set that you should get back should have that column labeled "Amount", since in the Select statement we gave that result column a name: ...sum(amt) as Amount... Robert Bradley
Sr. DBA, some big company
cheap prints and oil paintings:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top