sql - MySQL select the nearest lower value in table -
i have sql table stores running times , score associated each time on table.
///////////////////// / time * score / / 1531 * 64 / / 1537 * 63 / / 1543 * 61 / / 1549 * 60 / /////////////////////
this example of 4 rows in table. question how select nearest lowest time.
example: if records time of 1548 want return score 1543 (not 1549) 61.
is there sql query can use thank you.
use sql's where
clause filter records, order by
clause sort them , limit
(in mysql) obtain first result:
select score my_table time <= 1548 order time desc limit 1
see on sqlfiddle.
Comments
Post a Comment