0

I have been trying to figure out what kinds of aggregates I can use to create indexed view. FYI: I was I able to create one with SUM(). I also found that I can't create indexed view with MIN, MAX and AVG. How about others? It is possible? I couldn't find any info in the web also couldn't make it work on my comp.

Dilshod
  • 3,189
  • 3
  • 36
  • 67

2 Answers2

1

According to TechNet, scalar aggregates are supported in indexed views. As to why Min/Max are not supported, see this answer.

Community
  • 1
  • 1
devlin carnate
  • 8,309
  • 7
  • 48
  • 82
1

sqlmag.com says:

Do Index Sorting, Grouping, and Aggregating Columns

You also need to consider indexing columns that you use to order by and those that you use in a grouping expression. You might benefit from indexing the columns that the MIN(), MAX(), COUNT(), SUM(), and AVG() functions use to aggregate the data. When you use the MIN() and MAX() functions, SQL Server does a simple lookup for the minimum and maximum values in the column, respectively. If an index's data values are arranged in ascending order, SQL Server can read the index to quickly determine the correct values of MIN() or MAX(). The range-of-values query incorporates a filter or constraint (expressed in the SELECT query's WHERE clause or HAVING clause) to limit the rows that the query returns. Similarly, when you have an index, you can optimize data sorting (by using the ORDER BY clause) and data grouping (by using the GROUP BY clause), especially if the table or tables you're querying contain many rows.

Ahror Kayumov
  • 433
  • 4
  • 18