首页 \ 问答 \ 选择一个间隔的几个平均值(select several averages of an interval)

选择一个间隔的几个平均值(select several averages of an interval)

所以我的同事正在查看一个可以描述为这样的模式:

+--------------------+-----------+
| DATETIME timestamp | INT value |
+--------------------+-----------+

每隔5分钟输入一行,该值为该时刻的值。

这是它变得棘手的地方。 他希望在7天的间隔内获得每8小时的平均值。

当然,我可以想到涉及一些客户端代码的解决方案,我们想知道是否有可能在SQL中做更多。

所以从本质上说,他想:

SELECT timestamp, value
  FROM table
 WHERE timestamp >= NOW() - INTERVAL 7 DAYS 
   AND timestamp <= NOW();

然后将其分解为8小时块,并平均每个块的内容。 (每个块应该有12行,每天应该有3个块)。


So my coworker is looking at a schema which could be described as something like this:

+--------------------+-----------+
| DATETIME timestamp | INT value |
+--------------------+-----------+

Every 5 minutes a row is entered with the value for that moment.

Here's where it gets tricky. He wants to get the average of every 8 hour period within a 7 day interval.

Certainly, I can think of solutions which involve some client side code, we were wondering if it was possible to do more in SQL.

So in essence, he wants:

SELECT timestamp, value
  FROM table
 WHERE timestamp >= NOW() - INTERVAL 7 DAYS 
   AND timestamp <= NOW();

And then breaking that up into 8 hour blocks, and averaging the contents of each block. (each block should have 12 rows, and there should be 3 blocks per day).


原文:https://stackoverflow.com/questions/11743029
更新时间:2023-07-28 08:07

最满意答案

精确的条件在[[Construct]]内部属性中描述,由new运算符使用:

从ECMA-262第三。 版本规格:

13.2.2 [[Construct]]

当调用Function对象F[[Construct]]属性时,将执行以下步骤:

  1. 创建一个新的本地ECMAScript对象。
  2. Result(1)[[Class]]属性设置为"Object"
  3. 获取F的原型属性的值。
  4. 如果Result(3)是一个对象,将Result(1)[[Prototype]]属性设置为Result(3)
  5. 如果Result(3)不是一个对象,则将Result(1)[[Prototype]]属性设置为原始Object原型对象,如15.2.3.1所述 。
  6. 调用F[[Call]]属性,提供Result(1)作为this值,并将传递给[[Construct]]的参数列表作为参数值。
  7. 如果Type (Result(6))Object则返回Result(6)
  8. 退货Result(1)

查看步骤7和8,只有当Result(6)类型Result(6)F构造函数返回的值) 不是 Object时,才会返回新对象。


The exact condition is described on the [[Construct]] internal property, which is used by the new operator:

From the ECMA-262 3rd. Edition Specification:

13.2.2 [[Construct]]

When the [[Construct]] property for a Function object F is called, the following steps are taken:

  1. Create a new native ECMAScript object.
  2. Set the [[Class]] property of Result(1) to "Object".
  3. Get the value of the prototype property of F.
  4. If Result(3) is an object, set the [[Prototype]] property of Result(1) to Result(3).
  5. If Result(3) is not an object, set the [[Prototype]] property of Result(1) to the original Object prototype object as described in 15.2.3.1.
  6. Invoke the [[Call]] property of F, providing Result(1) as the this value and providing the argument list passed into [[Construct]] as the argument values.
  7. If Type(Result(6)) is Object then return Result(6).
  8. Return Result(1).

Look at steps 7 and 8, the new object will be returned only if the type of Result(6) (the value returned from the F constructor function) is not an Object.

相关问答

更多
  • 之前会处理返回值的复制初始化。 来自标准, $6.6.3/3 The return statement [stmt.return] (强调我的) 在返回语句的操作数所建立的完整表达式的末尾销毁临时对象之前,对返回实体的复制初始化进行排序,然后在返回语句的局部变量(6.6)封闭返回语句块 。 The copy-initialization of the returned value will be processed before. From the standard, [stmt.return]/3 (em ...
  • 否。只要return语句中的局部变量有资格进行复制检查,它将绑定到一个右值引用,从而return t; 与return std::move(t); 在你的例子中,哪些构造函数有资格。 注意return std::move(t); 防止编译器在return t执行复制检查; 不是,因此后者是首选的风格。 [感谢@Johannes的纠正。]如果复印错误发生,是否使用移动构造的问题成为一个难题。 见标准中的12.8(31,32)。 还要注意,如果T有一个可访问的副本,而是一个删除的移动构造函数,那么return ...
  • 构造函数实际发生的是,运行时使用编译器生成的类型数据来确定将对象实例存储在内存中(无论是在堆栈还是堆上)需要多少空间。 该空间包括所有成员变量和vtbl。 在分配此空间之后,构造函数被称为实例化和初始化过程的内部部分,以初始化字段的内容。 然后,当构造函数退出时,运行时返回新创建的实例。 所以构造函数不返回一个值的原因是因为它不是直接由你的代码调用的,它是由运行时内存分配和对象初始化代码调用的。 它的返回值(如果在编译到机器代码的时候实际上有一个)对于用户来说是不透明的,因此你不能指定它。 What act ...
  • 构造函数不会得到返回值; 他们完全可以实例化课程。 没有重组您已经在做的事情,您可以考虑在此使用例外。 public function __construct ($identifier = NULL) { $this->emailAddress = $identifier; $this->loadUser(); } private function loadUser () { // try to load the user if (/* not able to load user ...
  • 精确的条件在[[Construct]]内部属性中描述,由new运算符使用: 从ECMA-262第三。 版本规格: 13.2.2 [[Construct]] 当调用Function对象F的[[Construct]]属性时,将执行以下步骤: 创建一个新的本地ECMAScript对象。 将Result(1)的[[Class]]属性设置为"Object" 。 获取F的原型属性的值。 如果Result(3)是一个对象,将Result(1)的[[Prototype]]属性设置为Result(3) 。 如果Result( ...
  • 将@Mocked注释更改为@Capturing ,如下所示: @Capturing Collaborator collaborator; 这可以让我通过测试。 在我看来,这有点巫术魔法,但如果您想要阅读更多内容,请查看JMockit教程中捕获模拟类型的内部实例 。 另请参阅使用JMockit从模拟构造函数返回实际实例 Change the @Mocked annotation to @Capturing, like this: @Capturing Collaborator collaborator; ...
  • 一旦初始化,构造器就意味着将一个对象带到完全构造的结构中。 另一方面,异步方法和构造函数不能很好地发挥作用,因为构造函数是继承同步的。 解决此问题的方法通常是为类型提供初始化方法,该方法本身是异步的。 现在,你让调用者完全初始化对象。 请注意,这将要求您监视方法的实际初始化。 当你需要规模时,异步闪耀。 如果您不希望这会成为应用程序中的IO瓶颈,那么可以考虑使用同步方法。 一旦构造器完成执行,这会给你实际完全初始化对象的好处。 虽然,我不认为我会通过构造函数来启动对数据库的调用: public async ...
  • 是“添加”和“res”构造函数吗? 不add()是类X的成员函数并返回X , res是add()一个局部变量,类型为X 构造函数不能返回值 是的这是对的。 Are "add" and "res" constructors? No. add() is a member function of class X and returns X, res is a local variable inside add() with type X. constructors can't return a value Yes ...
  • 你的假设非常正确。 对于pass by value,对象在通常传递参数的位置构造,有时在调用函数之前(但在前一个语句之后),并在从函数返回之前被破坏,就好像它们是函数中的局部变量一样。 对于通过引用传递,对象在堆栈上构建(或者通常构造临时的任何地方),并在完整表达式的末尾被破坏。 对于返回值,对象由被调用函数构成,在return语句中(但在调用局部变量的析构函数之前),并由被调用者在完整表达式的末尾进行破坏。 Your assumtions are pretty much correct. For pass ...
  • 根据规范:如果调用构造函数返回一个对象,那么这个对象就是new -expression的结果。 如果构造函数未返回对象(但undefined或其他原始值),则结果是新创建的对象。 如果允许原语,那么所有构造函数都必须显式返回一些东西(通常是“ this ”),否则结果将是undefined (因为没有return的函数的结果是undefined )。 这将是一个不必要的麻烦。 此外,有意义的是可以依赖new来始终返回一个对象。 According to the spec: If calling the co ...

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)