1

我正在尝试使用“新命名查询”在 SSAS 的数据源视图中添加一个表。脚本如下所示:

Declare @AvgInvestment float;
SELECT  @AvgInvestment=SUM(Investment)/COUNT(distinct meta_ID)
FROM AAAA



SELECT        Player, Investment, 
              InvestmentRange=
              Case When Investment >=0 AND  Investment <(@AvgInvestment/3)                       THEN 1
                   When Investment >=(@AvgInvestment/3) AND  Investment <(4*@AvgInvestment/3)    THEN 2                           
                   When Investment >=(4*@AvgInvestment/3) AND  Investment <(6*@AvgInvestment/3)  THEN 3                         
                   When Investment >=(2*@AvgInvestment)                                          THEN 4
             END                              
FROM  AAAA 

但是,SSAS 不允许在 SQL Query for DVS 中声明变量。是否有任何可能的方法来修改 SQL 语句以使其没有变量?我尝试将 @AvgInvestment 替换为 "SELECT SUM(Investment)/COUNT(distinct meta_ID) FROM AAAA" ,但它不起作用。

感谢您提供任何可能的解决方案!

4

1 回答 1

1

你可以加入你的平均值,而不是使用变量。例如:

SELECT Player, Investment, 
       InvestmentRange=
       Case When Investment >=0 AND  Investment <(a.avg/3)              THEN 1
            When Investment >=(a.avg/3) AND  Investment <(4*a.avg/3)    THEN 2
            When Investment >=(4*a.avg/3) AND  Investment <(6*a.avg/3)  THEN 3                         
            When Investment >=(2*a.avg)                                 THEN 4
       END                               
FROM  AAAA cross join 
(select SUM(Investment)/COUNT(distinct meta_ID) as avg from aaaa) a

在数据源视图中完美运行。存储过程在那里不起作用。

于 2012-08-25T19:29:23.493 回答