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

时间:2018-05-24 11:41:40

标签: sql sql-server tsql sql-server-2005

我想要每个和每天的总行数想要连续的最大行计数,其中条件麻木> 2和校准!= 1来自下面的图表

manually implementing Send is unsafe already

和欲望输出应

The table structure

1 个答案:

答案 0 :(得分:2)

我认为你想要条件聚合:

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;