【问题标题】:Eliminate some big values while using SSRS MAX function使用 SSRS MAX 函数时消除一些大值
【发布时间】:2020-07-11 18:25:52
【问题描述】:

我有许多表使用 SSRS 每天从每个表的多行中导入最大值。 有时我们会得到一些异常读数,需要省略并使用下一个最大值。

例如:我有一个表格,其行中的值为“26,28,29,31,23,22,34,99999,27,20”。

所以最大值 = 99999,但我需要省略这个值,因为这是异常值,需要将最大值设为 34。

SSRS有什么方法可以做吗?

或者只是找出第二高值的解决方案?

【问题讨论】:

    标签: sql-server reporting-services ssrs-2012


    【解决方案1】:

    一种选择是创建标准化数字

    只是为了验证结果,归一化数的总和应该为零 +/- 一些精度。

    示例

    Declare @YourTable Table ([SomeVal] int)  
    Insert Into @YourTable Values 
     (26)
    ,(28)
    ,(29)
    ,(31)
    ,(23)
    ,(22)
    ,(34)
    ,(99999)
    ,(27)
    ,(20)
     
    
    ;with cte as (
    Select *
          ,NormNbr=([SomeVal]-avg([SomeVal]) over()) / stdev([SomeVal]) over()
     From @YourTable
    )
    Delete from cte where abs(NormNbr)>1   -- You may want to tweak as needed
    
    Select * from @YourTable
    

    更新后的表格是

    SomeVal
    26
    28
    29
    31
    23
    22
    34
    27
    20
    

    或者如果您不想删除异常行

    ;with cte as (
    Select *
          ,NormNbr=([SomeVal]-avg([SomeVal]) over()) / stdev([SomeVal]) over()
     From @YourTable
    )
    Select MaxValue = max([SomeVal])
     From  cte 
     Where abs(NormNbr)<=1
    

    退货

    MaxValue
    34
    

    编辑:如果您要在 CTE 中运行查询,这就是您所看到的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-15
      • 2018-02-09
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多