I am trying to find those Donors who donated more than an average number of times. I would have thought that the Count function would pass an integer to the AVG function but I’m missing something as I get this error:
Msg 8117, Level 16, State 1,Line 1
Operand data type varchar is invalid for avg operator.
SELECT AVG(’TotalTimesDonating’) AS ’AverageTimesDonating’
,[Donors] AS ’DonorNames’
FROM DonorsTable
WHERE EXISTS
(
SELECT [Donors] AS ’DonorNames’
,COUNT([Donors])AS ’TotalTimesDonating’
FROM DonorsTable
GROUP BY ’DonorNames’
)
GROUP BY [DonorNames]
HAVING ’TotalTimesDonating’>’AverageTimesDonating’
I am completely new to SQL. Any and all suggestions appreciated!
Meleia