获得平均值数组的最佳方法? [英] Best way to get an array of average values?

查看:100
本文介绍了获得平均值数组的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个解决方案,可在一分钟内多次将当前能耗值(kW)存储到sql表中.该应用程序正在24/7运行.

我需要根据每分钟的平均消耗量显示图形,因此首先我需要获取每分钟内的平均值.最后,结果应该是1440(= 60 * 24)个值的数组,对应一天中的每一分钟.

我的问题是,我可以摆脱使用SQL语句的烦恼吗,还是应该只检索白天的所有值,并分别在C#中处理数据,并基于计算来创建数组?

例如,通过以下语句,我将在一分钟内获得所有值的平均值:

I have a solution which stores current energy consumption values (kW) to sql table several times in one minute. The application is running 24/7.

I would need to show graphics based on each minute average consumption, so first I need to get an average of values within each minute. Finally the result should be an array of 1440 (=60*24) values, corresponding each minute in one day.

My question is, can I get this out of using SQL statement, or should I just retrieve all values during the day, and process the data separately in C#, and create the array based on calculations?

As an example, I''ll get an average of all values in a minute with this statement:

SELECT AVG (KL_Energy) FROM [HomeControl].[dbo].[Home] where Day= ''2012-01-04'' and Time >= ''21:24'' and Time < ''21:25''



我不想一天重复1440次:)

感谢您的帮助.



I wouldn''t like to repeat this 1440 times for a day :)

Thanks for any help.

推荐答案

SELECT Day, DATEPART(min, Time), AVG(KL_Energy) FROM Home GROUP BY Day, DATEPART(min, Time) HAVING Day='...'

大桌子.试试看,我现在不能尝试.

It might take some time for big table. Give it a try, I cannot try it now.


感谢您的快速回复!

我将min更改为mi,它实际上为我提供了一系列值!谢谢!

我仍然需要改进的是将实际时间"值包括在列表中.现在就像:
Thanks for your quick response!

I changed min to mi, and it actually gives me an array of values!! Thanks!

What I would still need to improve is to include the actual Time value to the list. Now it is like:
2012-01-04	0	3126
2012-01-04	1	3070
2012-01-04	2	3111
...


没有显示计算出的平均价值的分钟数.如果确实存在所有值,则不需要此操作,但有时由于Windows启动,某些分钟内将没有值.

为时间添加另一列很容易吗?

再次感谢.


not showing the minute of the avg value calculated. This wouldn''t be needed if there allways is really all values, but sometimes, due to, say windows boot up, there will be no values for certain minutes.

Is it easy to include another column for Time?

Thanks again.


这篇关于获得平均值数组的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆