Mysql Query - Get the next value greater than 0

1

Example, I need the query to return these circled values. The previous result was 0 (zero). The current one does not. I need to get the current value. And list

    
asked by anonymous 26.05.2017 / 20:49

1 answer

1

If you make sure there are no "holes" in your id field, then the solution below will show you the results you want:

SELECT *
  FROM tabela t
 WHERE t.Velocidade > 0
   AND (SELECT t2.Velocidade
          FROM tabela t2
        WHERE t2.id = t.id - 1) = 0

Or, in the case of the field id have some "jump":

SELECT *
  FROM tabela t
 WHERE t.Velocidade > 0
   AND (SELECT t2.Velocidade
          FROM tabela t2
         WHERE t2.id < t.id
         ORDER BY t2.id DESC
         LIMIT 1) = 0
    
26.05.2017 / 20:54