1

我试图找到语法来计算存储过程中一组变量的标准偏差。

我希望能够做这样的事情:

set variable1 = 5;
set variable2 = 7;
set variable3 = 8;
set variable4 = 2;

set MyStandardDeviation = StdDev(variable1, Variable2, variable3, variabl4)
4

1 回答 1

2

您可以使用UNION ALL组合和生成一列临时表,

set variable1 = 5;
set variable2 = 7;
set variable3 = 8;
set variable4 = 2;

set MyStandardDeviation = 
            (
                SELECT StdDev(x.Val)
                FROM 
                    (
                        SELECT variable1 As Val
                        UNION ALL
                        SELECT variable2 As Val
                        UNION ALL
                        SELECT variable3 As Val
                        UNION ALL
                        SELECT variable4 As Val
                    ) x
            );
于 2012-10-21T15:08:09.550 回答