mysql - Select date where there is data in-between -
i have todayrainsofar column filled db every minute, , find out maximum duration of rain month, ie when started rain , how long did last.
for example started rain 2014-04-01 @ 08:00 , raining without pause until 2014-04-05 10:00
i have trouble combined queries.
// select rows when there rain month select logdatetime, todayrainsofar sibeniku_monthly todayrainsofar > 0.0 , date_format(logdatetime, "%m.") = 04
now looking count maximum duration of in-between rows (logdatetime datetime , range 1 minute), smth like
and max (count between rows)
the approach used below keep counter of consecutive minutes of rain , row has maximum value of counter (this give maximum duration of consecutive rain). counter reset 0 if rain has ended.
select date_sub(logdatetime, interval counter minute) starttime, logdatetime endtime ( select if(todayrainsofar = 0, @i:=0, @i:=@i+1) `counter`, logdatetime, todayrainsofar sibeniku_monthly, (select @i:= 0) order logdatetime ) t order `counter` desc limit 0,1
working demo: http://sqlfiddle.com/#!2/8578b8/8
Comments
Post a Comment