-1

Is it possible in mysql to find extremes values I have table with columns (timestamp, value) and I have to detect when values started to increased and decreased and notice that value.

I.e with this datas

2015-05-14 04:40:00, 1000
2015-05-14 05:20:00, 2000
2015-05-14 08:00:00, 2500
2015-05-14 08:20:00, 500
2015-05-14 09:10:00, 700
2015-05-14 10:20:00, 700
2015-05-14 11:40:00, 1300
2015-05-14 12:10:00, 1800
2015-05-14 12:40:00, 2700
2015-05-14 13:20:00, 3500
2015-05-14 14:10:00, 500
2015-05-14 14:30:00, 700
2015-05-14 14:50:00, 1000

I need to find 2015-05-14 08:00:00, 2500 as max and

2015-05-14 08:20:00, 500 as min and second point
2015-05-14 13:20:00, 3500 as max
2015-05-14 14:10:00, 500 as min

I want to find only extreme values so I need to find only rising and trailing edge.

Data are represented in that way http://fastwork.pl/karol/wykres_extrema.png

2 Answers 2

0

You can simply use MIN and MAX

SELECT *
FROM yourTable
WHERE value = (SELECT MIN(value)
               FROM yourTable);

And it works the same for MAX.

0

Not full answer. But for selecting only growing values you can use:

SELECT t2.val
FROM `test` t1
JOIN `test` t2 ON ( t1.id = t2.id -1
AND t1.val < t2.val ) 

You need to add id primary autoincrement field

Now you need to find hole in this data https://www.google.com/search?q=mysql+holes

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.