tags:

views:

29

answers:

1

I have this query which works perfectly:

SELECT cp.*
FROM CustPrimaryQ cp
    JOIN Customer c ON cp.CxID = c.CustomerID
    JOIN SacCode sc ON sc.SacCode = c.SacCode
WHERE sc.ResellerCorporateID = 392

However I am trying to modify it to calculate an average.

Each row of the CustPrimaryQ table has a field called QScore and it's this field I want to find out the total average of.

In other words if there are 10 rows in CustPrimaryQ I want the Average QScore for the 10 rows.

Any help would be much appreciated.

+5  A: 

It depends on the relationship among the three tables. But if your current query is guaranteed to return the records you want to average, all you have to do is:

SELECT AVG(QScore)
FROM CustPrimaryQ cp
JOIN Customer c ON cp.CxID = c.CustomerID
JOIN SacCode sc ON sc.SacCode = c.SacCode
WHERE sc.ResellerCorporateID = 392
Larry Lustig
I'm so think. Of course it's that.
Oliver