I am trying to show average values, then join the returned average values to a second table that shows a description for the average value.My first problem is that I can't work out how to join on the average value. Can anyone help with this?The error I get is:An aggregate cannot appear in an ON clause unless it is in a subquery contained in a HAVING clause or select list, and the column being aggregated is an outer reference.
Secondly, the average values are calculated using a column of type INT. Will the average values automatically be calculated as INT's, or will there be a decimal place. If there is a decimal place, how do I round to the nearest INT so that the JOIN works correctly? My query is:SELECT AVG(t.overallResultID) as [average], t.[name], t.surname, t.pdruiID, ior.overallResultFROM @tmp t INNER JOIN [tbl_OverallResults] ior ON ior.ID = AVG(t.overallResultID) -- error here!GROUP BY t.pdruiID, t.surname, t.[name]
Thanks.