1

我需要一个查询来查找按日计算的列的标准差。我的表有大约 30,000 行,时间戳为每 10 分钟一次。请在下面的示例数据中找到时间戳和 TF 列。我还需要得到其余列的偏差

Timestamp                  TF
2012-05-17 19:15:35.000    10
2012-05-17 19:25:35.000    10
2012-05-17 19:35:35.000    10
2012-05-17 19:45:35.000    10
2012-05-17 19:55:35.000    10
2012-05-17 20:05:35.000    10
2012-05-17 20:15:35.000    10
2012-05-17 20:26:46.000    10
2012-05-18 00:06:48.000    10
2012-05-18 00:16:48.000    10
2012-05-18 00:26:48.000    10
2012-05-18 00:36:48.000    10
2012-05-18 00:46:48.000    10
2012-05-18 00:56:48.000    10
2012-05-18 01:06:48.000    10
2012-05-18 01:16:48.000    10
2012-05-18 01:26:48.000    10
2012-05-18 01:36:49.000    10

需要输出为

Timestamp        TF
2012-05-17     0
2012-05-18       0
---             --
---             --
---             --
---             --

请帮忙!!提前致谢!!

有任何想法吗?

4

1 回答 1

1

编辑:我转置DAYDATEDAY返回月中的日期;DATE返回截断到当天的时间。答案已更新以包含该修复程序。

您将需要使用聚合函数,按天分组:

SELECT DATE(Timestamp), STDDEV(TV) FROM MyTable GROUP BY DATE(Timestamp);

我假设有一个DATE()功能。

可能没有STDDEV功能。如果没有 ,STDDEV(x)=SQRT(AVG((x-AVG(x))^2)可能必须作为连接子查询来实现:

SELECT DATE(Timestamp), SQRT(AVG((a.TF-b.mean)*(a.TF-b.mean)) FROM MyTable a LEFT JOIN
    (SELECT DATE(Timestamp) day, AVG(TF) mean FROM MyTable GROUP BY DATE(Timestamp)) b
        ON DATE(a.Timestamp)=b.day 
    GROUP BY b.day;
于 2012-12-17T05:31:08.753 回答