计算每天总行数中的最大连续行数Ms Sql

计算每天总行数中的最大连续行数Ms Sql,sql,sql-server,tsql,sql-server-2005,Sql,Sql Server,Tsql,Sql Server 2005,我想要每一天的总行数,并且想要连续的最大行数,条件numb>2且校准=1来自下图中的表 而欲望输出应该是 我认为您需要条件聚合: 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; 选择todaydate,将(*)计数为

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

而欲望输出应该是

我认为您需要条件聚合:

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;
选择todaydate,将(*)计数为totalrow,
求和(当(numb>2和校准1)时,则为1,否则为0结束)为[max]
来自表t
按今日日期分组;

如果答案正确,请务必接受,@priyankacharya