-1

I've following values in my database:

Column1
-----
 10
 20
 30
 05
 12
 21
 10
 40

As you can see, the value is increasing in the first three rows. It starts again in the fourth row with some value like 5. and then starts again in the 7th row with 10, for example. That is, it lowers and then increases again to some extent. The value starts with different numbers. I want to get the highest of each. i.e. I want to get rows with value 30,21, and 40.

Note that I've only the sorted list, It can be done with some variable in programming language but how to do this in mysql with some query?

2

1 Answer 1

0

I would insert all the values into another table which will have only 2 columns (id AUTOINCREMENT and Val as your values).

And then I would use this select:

SELECT
Val
FROM (
  SELECT
      T1.id, T1.Val, (Select Val from MyTable T2 where T2.id = T1.id + 1) NextVal
  FROM 
      MyTable T1
)
WHERE
Val > NextVal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.