Finally, the problem was fixed by the following mysql query:
select min(a.mydate),max(a.myhigh) as high,min(a.mylow) as low, min(case when rn_asc = 1 then a.myopen end) as open, min(case when rn_desc = 1 then b.myclose end) as close from( select @i := if((@lastdate) != (Floor(unix_timestamp(mydate)/300 )), 1, @i + 1) as rn_asc, mydate, myhigh, mylow, myopen, myclose, @lastdate := (Floor(unix_timestamp(mydate)/300 )) from onemindata_1, (select @i := 0) vt1, (select @lastdate := null) vt2 order by mydate ) a inner join( select @j := if((@lastdate1) != (Floor(unix_timestamp(mydate)/300 )), 1, @j + 1) as rn_desc, mydate,myclose, @lastdate1 := (Floor(unix_timestamp(mydate)/300 )) from onemindata_1, (select @j := 0) vt1, (select @lastdate1 := null) vt2 order by mydate desc )b on a.mydate=b.mydate group by (Floor(unix_timestamp(a.mydate)/300 ))
The hardest part was getting Open and Close for the "Specific Time Intervals". I am doing the inner join "high, low, open" from "close" to "date". I can switch the time intervals by changing the denominator to (Floor (unix_timestamp (mydate) / 300)). Currently not worried about performance while it works :).
source share