The easiest way I can think of to do it is to create a view grouping on 
account and then sum from the view.

create view myview (account,max_budget) as +
select account, (max(budget)) from mytable group by account

select sum (max_budget) from myview

There may be a more creative way to do this in a single statement.

Troy


------ Original Message ---------

sorry, i didnt phrase my question correctly.  If i have:
 
Account Budget
1              30
1              30
2              40
2              40
3              20
3              20
 
i want the sum of the distinct account budgets...IE: 30+40+20=90 so i want 
it to display 90 as the result.  Is this doable?
 
sorry, i didnt phrase my question correctly.  If i have:
 
Account Budget
1              30
1              30
2              40
2              40
3              20
3              20
 
i want the sum of the distinct account budgets...IE: 30+40+20=90 so i want it to display 90 as the result.  Is this doable?
 
----- Original Message -----
From: randyp
Sent: Thursday, October 10, 2002 12:26 PM
Subject: Re: newbie sql question

SELECT account, SUM(budget) from [tableName] group by account.
 
This will show you the sum of however many budget amounts for each distinct account. 
 
Account    Budget
1                $ 200
1                    300
2                    100
 
will result in:
1                $ 500
2                    100
 
If you use SUM(budget)=s the total of $ 600 will be listed underneath the individual budget subtotals.
 
        Randy Peterson
----- Original Message -----
Sent: Thursday, October 10, 2002 2:39 PM
Subject: newbie sql question

i know this is more of an sql question (and a newbie one at that) than an rbase question but im having a problem tryin to figure this out.
 
I have a table with 2 columns...1 is Account and the other is Budget.  What i need is a sum of Budget, but there are duplicate entries so i need it to sum Budget where Account is distinct.  Anyone know how to do this?
 
thanx for the help!

Reply via email to