I am trying to create an indexed view with using aggregate AVG, but can't make it work. Has anybody tried doing it? I found this article but couldn't figure out how to make it work. Here is my script:
CREATE VIEW MyView
WITH SCHEMABINDING
AS
SELECT
Id, AVG(Age) as AvgAge, COUNT_BIG(*) as CountBig
FROM
dbo.Student
GROUP BY
Id;
GO
CREATE UNIQUE CLUSTERED INDEX MyIndex ON MyView(Id);
I understand MIN
and MAX
are not possible, but why not AVG
?