Board index » delphi » How do you sum averages in SQL

How do you sum averages in SQL

Hello:

I have a grid which displays the average loan balance, etc, of each client
for the month. Here is the SQL which derives these values:

<snip>
select cltacct, acct, count(cltacct) as DayCount,
avg(balance) as AvgLoan, avg(interest) as AvgInt
from daily.dbf
where acct > 1999 and acct < 8000
and daily.dbf."valuedate" between :mstart and :mend
group by cltacct,acct
order by cltacct
<snip>

Now I would like to total these averages to compute the average total loan
balance, but I don't know how. Is there a way to write an SQL statement
which will compute this? Example: sum(avg(balance))

Thanks for any ideas,

Rob.

 

Re:How do you sum averages in SQL


Quote
>Now I would like to total these averages to compute the average total loan
>balance, but I don't know how. Is there a way to write an SQL statement
>which will compute this? Example: sum(avg(balance))

What you do depends on what database you are using.  I will assume Paradox or
dbase.   If that is the case you need to do two queries.  
You can use the BDE Api method dbiMakePermanent to create a table from a query
so you can use it in a second query

DbiMakePermanent(query1.handle, 'temp.db',true);
Unless you specify a directory dbiMakePermanent will create the table in your
PrivateDir
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:How do you sum averages in SQL


Thanks, Brian.

Other Threads