mysql - SQL query select first from index -


i looking sql query following:

index   b  1    5   1  2    10  1  3    15  0  4    10  0  5    20  1  6    5   0  7    15  1  8    25  0  9    20  0  10   15  0 

selects "entry" row b 1, looks 1st next row point downwards, "exit" row, either entry value +10 , more, or -10 , more, doesn't matter value of b in "exit" row. return entry index, exit index, , indicator if exit +10 or -10 great, if not possible, nwm. in case, output of query should be

entryindex exitindex +10/-10 1 3 +10    //entry in line 1, because b 1, exit on line 15, because 15 5 +10 2 5 +10 5 6 -10 7 8 -10 

quick attempt using sub query:-

select t1.index entryindex,         t2.index exitindex,         if(t1.a <= t2.a, '+10', '-10') '+10/-10' (     select t1.index t1_index,             min(t2.index) t2_index     a_table t1     inner join a_table t2     on t1.index < t2.index     , (t1.a <= t2.a - 10     or t1.a >= t2.a - 10)     t1.b = 1     group t2.index ) sub0 inner join a_table t1 on t1.index = sub0.t1_index inner join a_table t2 on t2.index = sub0.t2_index 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -