sql - mysql count zeros in sequence -
i got mysql database , need number of zeros in sequence , print them date first zero, example got table this
id, date, impuls_count 1, '12-05-15 12:00:00', 60 2, '12-05-15 12:01:00', 0 3, '12-05-15 12:02:00', 0 4, '12-05-15 12:03:00', 49 5, '12-05-15 12:04:00', 0 6, '12-05-15 12:05:00', 0 7, '12-05-15 12:06:00', 0 8, '12-05-15 12:07:00', 0 9, '12-05-15 12:08:00', 30 10, '12-05-15 12:09:00', 0
this should give result this:
'12-05-15 12:01:00', 2 '12-05-15 12:04:00', 4 '12-05-15 12:09:00', 1
i tried solve on own query works slow(i got 5000 rows in table) , prints same row twice
select qwe.date, ile (select p.date, (select count(*) performance_v2 date > p.date , date < (select min(date) performance_v2 date > p.date , impuls_count > 0)) ile performance_v2 p p.impuls_count > 0 , (date(p.date) between '2015-05-08%' , '2015-05-08%') , (time(p.date) between '14:00:00' , '22:00:00') order 1) qwe ile > 0
in mysql, easiest solve using variables. idea have counter increment each time value of impuls_count
changes. defines groups of common values. can filter values , aggregate want:
select min(date), count(*) (select t.*, (@g := if(@ic = impuls_count, @g, if(@ic := impuls_count, @g + 1, @g + 1) ) ) grp table t cross join (select @ic := 0, @g := 0) order id ) t impuls_count = 0 group grp
Comments
Post a Comment