SQL:计数器上的警报和重复

SQL:计数器上的警报和重复,sql,Sql,我想用sql查询计算警报 数据收集如下,我有2个月的历史数据和4000名客户: 收集日期:2017年11月2日 注意:2 参考:CCC123 我想列出过去3天内超过阈值(nb\u reboot=3)的客户(ref\u custom)。对于SQL Server: select ref_custom from your_table where nb_reboot > MAX_REBOOT and date_collection >= dateadd(day, -3, getd

我想用sql查询计算警报

数据收集如下,我有2个月的历史数据和4000名客户:

收集日期:2017年11月2日 注意:2 参考:CCC123

我想列出过去3天内超过阈值(nb\u reboot=3)的客户(ref\u custom)。

对于SQL Server:

select ref_custom
from your_table
where nb_reboot > MAX_REBOOT
      and date_collection >= dateadd(day, -3, getdate());

希望我正确地理解了你的问题

对于PostgreSQL, 我想你可以用下面的查询

select ref_custom ,sum(nb_reboot) nb_reboot
from test_so
where date_collection>  current_date - interval '3' day
group by ref_custom
having sum(nb_reboot)>=3;
下面是sqlfiddle屏幕截图


您使用的是哪种dbms?示例数据和期望的结果也会阐明您想要做什么。我编辑了问题并添加了图像。感谢您的回答,但查询不起作用。我添加了示例(屏幕截图)和预期结果。因此预期结果应该是custom1、custom2,因为它们连续3天达到阈值@Tajinder@McNets:我尝试了以下两个查询,但它不起作用:选择ref_custom from Reboot,其中nb_Reboot>3和CollectionTime>=dateadd(day,-3,getdate。我有一个错误“函数不存在。@mcnets您正在使用什么RDBMS?Heisql。您建议我使用哪一个?@TajinderI'使用now Mysql workbench,我仍然有相同的错误。“函数docsis.dateadd不存在”@Tajinder@McNets