priyank acharya
priyank acharya

Reputation: 19

Count maximum consecutive row out of total row for each day Ms-Sql

I Want total number of row for each and for each day want consecutive max row count where condition numb>2 and calibration!=1 from table in pic below

The table structure

and desire output should be

The desired output

Upvotes: 1

Views: 55

Answers (1)

Yogesh Sharma
Yogesh Sharma

Reputation: 50163

I think you want conditional aggregation:

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;

Upvotes: 2

Related Questions