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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -