MYSQL - how to get previous row value if current value is zero -


i have table called value_record below

id | record_id | value | servertime 1  |     20    |   0   |  2016-04-19 04:51:16 2  |     20    |   0   |  2016-04-19 04:40:19 3  |     20    |   0   |  2016-04-19 04:27:34 4  |     20    |   70  |  2016-04-19 04:14:24 5  |     20    |   50  |  2016-04-19 04:02:21 

..

select value value_record record_id in(20)  order servertime desc limit 1; 

output :

0 

but expected output is:

70 

it means if current value 0 query go previous row not 0 , display non 0 value.

how achieve in mysql?

you need filter values different 0 , don't need in clause:

select     `value`     value_record     record_id = 20     , `value` > 0 order     servertime desc limit 1; 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -