mysql - Loop in a form of sql query -


i don't know start post example need:

a   b 5   0 10  0 15  0 20  0 25* 1* 30  0 35  1 40  1 45* 0 50  0 55  0 60  0 65  0 70  1 75  1 80  0 85  0 

i need query 1 in column b (first row found in 25 1),"entry point" point, go down , first column a, 20 more a in start point - "exit point" (found row 45 0), return row index of "entry point" , "exit point" , in case 25 1 , 45 0 rows.

also, tricky part might be, don't want row 35 1 or 40 1, contains 1 in b column, don't want rows in between entry , exit points, next applicable row row 70 1 entry point (75 1 be)

this able in java loop without problem, getting lower performance like, it's been suggested using db kind of operation should faster. possible such db query?

if understand corectly need first valid entry point , first valid exit point, should job

    select     (         select             min(a)                     table                     b = 1     ) entry,     exit,     table     + 20 >= (select             min(a)                     table                     b = 1) ,     b = 0 limit 1 

Comments