sql-server - Standard Deviation of a Row
问题描述
How do I find the standard deviation of a row in SQL Server? I'm trying to find the standard deviation for the image below but I'm unsure how.
Would I do STDEV on the total of the row? I'd want another column at the end showing the standard deviation for the entire year. I saw in Excel someone did =(STDEV(C4:N4)).
解决方案
Aggregate functions such as SUM
or STDEV
operate over rows.
You can use CROSS APPLY
to unpivot the columns to rows to calculate an aggregate on them
SELECT t.*,
ca.StdDev
FROM YourTable t
CROSS APPLY (SELECT STDEV(Val)
FROM (VALUES (JANUARY),
(FEBRUARY),
(MARCH),
(APRIL),
(MAY),
(JUNE),
(JULY),
(AUGUST),
(SEPTEMBER),
(OCTOBER),
(NOVEMBER),
(DECEMBER) ) v(Val)) ca(StdDev)
推荐阅读
- functional-testing - 如何在 appbuild 上测试模型级触发器?
- python - 将 Spyder 升级到 4.0.1 时出错:ModuleNotFoundError: No module named 'IPython.core.inputtransformer2'
- android - 如何在 JNI 中编辑 jobjectArray 并将其传递回 Java
- amazon-web-services - 如何使 ip 指向 AWS 上的其他 ip 和端口(来自两个 apache 虚拟主机)
- javascript - 我可以在 JavaScript 中声明变量的地方
- electron - 在 Electron 的“appData”中写入文件。在哪里添加 import { app } from "electron";?
- docusignapi - DocuSign API 方法信封.listStatusChanges 不显示共享给我的用户的信封
- ios - 如何让我的 UIButton 标题有一些填充?
- javascript - 如何将函数作为 React Native 中的属性传递给组件
- excel - 在具有不同名称的工作簿之间复制