创建索引视图时出错

时间:2013-09-11 16:25:50

标签: sql sql-server

我使用Schemabinding创建此视图:

CREATE VIEW RANKING_OPTIMIZATION_VIEW
WITH SCHEMABINDING
AS
  SELECT USERS.[USER_ID],
         USERS.GAMERTAG,
         CLASSIFICATION.WIDGET_ID,
         CLASSIFICATION.CLASSIFICATIONTYPE_ID,
         ROW_NUMBER() OVER(PARTITION BY CLASSIFICATION.WIDGET_ID, 
                                        CLASSIFICATION.CLASSIFICATIONTYPE_ID 
                               ORDER BY CLASSIFICATION.[SCORE] DESC ) AS RANKING,
         CLASSIFICATION.WIN,
         CLASSIFICATION.LOSE,
         CLASSIFICATION.SCORE
  FROM   [dbo].[GMW_CLASSIFICATION] AS CLASSIFICATION
         INNER JOIN [dbo].[GMW_USERS] AS USERS
           ON USERS.[USER_ID] = CLASSIFICATION.[USER_ID]
         INNER JOIN [dbo].[GMW_WIDGET_GAMETYPES] AS GAMETYPE
           ON GAMETYPE.[WIDGET_ID] = CLASSIFICATION.[WIDGET_ID]
              AND GAMETYPE.[GAMETYPE_ID] = CLASSIFICATION.[CLASSIFICATIONTYPE_ID] 

我收到了这个错误: 无法在视图“GameRoomDev.dbo.RANKING_OPTIMIZATION_VIEW”上创建索引,因为它包含排名或聚合窗口函数。从视图定义中删除该函数,或者,不要为视图编制索引。

任何想法如何更改查询? 感谢

1 个答案:

答案 0 :(得分:0)

在索引视图中阅读以下内容以获取允许的内容 http://technet.microsoft.com/en-us/library/ms191432(v=sql.100).aspx 你觉得使用Rowset函数。