0

我有一个查询,我试图在 SSRS 中创建一个数据集,但我收到一条错误消息,

The OVER SQL construct or statement is not supported.

我正在使用的查询如下:

SELECT AM, REP, PRIM_SPEC, SUM(TOT_CALL)
FROM (
       SELECT AM, REP, SUM(TOT_CALL) as TOT_CALL, 
       CASE 
           WHEN ROW_NUMBER() OVER (PARTITION BY REP ORDER BY SUM(TOT_CALL) DESC) > 5 
           THEN 'Other'
           ELSE prim_spec
       END AS prim_spec
       FROM DEMO_CALL
       WHERE PERIOD >= @Mese
       AND (REP IN (@REP)) 
       AND (AM = @AM)
       GROUP BY AM, REP, prim_spec
) A
GROUP BY AM, REP, PRIM_SPEC
ORDER BY 1,2,4 DESC

我如何使用我的 OVER SQL 构造来解决这个问题?

4

1 回答 1

1

这不是 SSRS 的问题,而是 SQL 语句本身的问题。在生成之前,您无法比较 ROW_NUMBER。试试这个:

SELECT distinct AM, REP, TOT_CALL, 
CASE 
   WHEN RN > 5 
   THEN 'Other'
   ELSE prim_spec
  END AS prim_spec
FROM (
 SELECT AM, REP, SUM(TOT_CALL) as TOT_CALL, ROW_NUMBER() OVER (PARTITION BY REP ORDER BY SUM(TOT_CALL) DESC) as RN
 FROM DEMO_CALL
 WHERE PERIOD >= @Mese
   AND (REP IN (@REP)) 
   AND (AM = @AM)
 GROUP BY AM, REP
) DEMO_CALL
GROUP BY AM, REP, prim_spec
ORDER BY 1,2,4 DESC
于 2016-07-27T19:54:16.440 回答