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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Average over results from query

Status
Not open for further replies.

KeesSmit

Programmer
Sep 10, 2007
1
I would like to write a query in which i calculate the average over the result from an earlier query.
I have a transaction header table and a separate transaction lines table. I am trying to count an amount per transaction by summing the lines table, grouped by transactionnumber and would like to calculate the average over all of these sums.
Any suggestion?
Im using a Mysql that doesn't support VIEWs
 
Code:
SELECT AVG(amt_per_trans) AS avg_amt_per_trans
  FROM (
       SELECT TH.transactionnumber
            , SUM(TL.amount) AS amt_per_trans
         FROM transaction_headers as TH
       INNER
         JOIN transaction_lines AS TL 
           ON TL.transactionnumber = TH.transactionnumber
       GROUP
           BY TH.transactionnumber
       ) AS trans_totals

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top