首页 > 解决方案 > 计算每天 Ms-Sql 总行中的最大连续行

问题描述

我想要每天和每一天的总行数想要连续的最大行数,其中条件 numb>2 和校准!= 1 来自下图中的表格

表结构

和期望的输出应该是

所需的输出

标签: sqlsql-servertsqlsql-server-2005

解决方案


我认为你想要条件聚合:

select todaydate, count(*) as totalrow,
       sum(case when (numb > 2 and calibration <> 1) then 1 else 0 end) as [max]
from table t 
group by todaydate;

推荐阅读