简体   繁体   English

SQL Server存储过程可分析实时流数据并报告差异

[英]SQL Server stored procedure to analyze live streaming data and reporting differences

I have a live data stream on a 2 minutes interval, that I wish to analyze in (near) real time. 我每隔2分钟就有一个实时数据流,我希望(近)实时分析。 A snippet of this data is shown here: 此数据的片段显示在此处:

以2分钟间隔的DataSnippet

This data is getting stored in a SQL Server table. 此数据将存储在SQL Server表中。

Now, I am trying to code a stored procedure in SQL Server 2008 that fulfills this condition: 现在,我正在尝试在满足以下条件的SQL Server 2008中编写存储过程:

Highest - Max(Start,End) > Absolute Value(Start - End),

ITEM3 fulfills this condition. ITEM3满足此条件。

Additionally, for ALL the items which fulfill the above condition, it should then go back in time and return the start of the first record which fulfills the condition of End (Value) > Start (Value) 此外,对于满足上述条件的所有项目,它应及时返回并返回满足“ End (Value) > Start (Value) ”条件的第一个记录的开始。

So, in the case above, the value returned should be 209.1 & Item 3. 因此,在上述情况下,返回的值应为209.1项目3。

The condition is getting fulfilled for ITEM3 only in the above case @10:21 AM 仅在上述情况下@上午10:21满足ITEM3的条件

Additional note: for the purpose of this query, the values of lowest are not being used. 附加说明:出于此查询的目的,未使用最低值。

Also, there are no Zero / Null values in this data stream (the .. is temporarily there). 另外,此数据流中没有零/空值(..暂时存在)。

With my limited knowledge on SQL subqueries etc, I am unable to get the desired result beyond the first condition. 由于我对SQL子查询等的了解有限,因此我无法获得超出第一个条件的期望结果。

select desc 
from table1                     
where Highest - dbo.InlineMax(Start,End) > abs(Start- End)  

InlineMax is my UDF which returns the higher value. InlineMax是我的UDF,它返回较高的值。

TIA TIA

This should get you what you want. 这应该给您您想要的。

SELECT 
    [desc], [highest], [start], [end]
FROM 
    items
GROUP BY 
    [desc], [highest], [start], [end]
HAVING
    (MAX([start]) > MAX([end]) and highest - MAX([start]) > ABS([start]-[end]))
    OR
    (MAX([start]) <= MAX([end]) and highest - MAX([end]) > ABS([start]-[end]))

group by the relevant columns and then filter it out using the having clause. 按相关列进行分组,然后使用hading子句将其过滤掉。

  • If max(start) > max(end) then require highest - max(start) > abs(start-end) 如果max(start)> max(end),则要求最高-max(start)> abs(start-end)
  • If max(start) <= max(end) then require highest - max(end) > abs(start-end) 如果max(start)<= max(end)然后要求最高-max(end)> abs(start-end)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM