Mysql query - Take the next value greater than 0

Asked

Viewed 918 times

1

Preciso fazer uma consulta Mysql que me retorne o próximo valor que não seja 0 após zero

Example, I need the query to return me these circulated values. The previous result was 0 (zero). The current one is not. I need to take the current one. And list

1 answer

1


If you ensure that there are no "holes" in your field id, 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 camp id possess 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
  • Thank you very much friend! That was exactly it ..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.