Thursday 15 May 2014

sqlite - An sql statement to select the closest values -


In the table below, I will call Table A. There are two numerical columns. I need to make a selection statement by which The value of B is specified. Either one or two rows are returned, not sure that it can be done in a single SQL statement. If a line exists, where B is the value of the match, then just that line has been returned if the value of B is between the two values ​​of B, which is closest to its value, both values ​​have returned if any Value exists which is larger than that but is not bigger than that value which is returned to a larger value if a larger value is not present but makes one smaller, then the row with the small value Back to Or Here are some examples. It would be nice if SQL sqlite worked in:

  AB 50 400 10 200 30 100 40 800 20 500 B = 10 AB 30 100 ---------- B = 250 Abby 10 200 50 400 ---------- B = 100 AB 30 100 ---------- B = 410 AB 50 400 20 500 ---------- Select B = 900 Abi 40 800    

  where from B = Selection of 10 units * from where select the unit from B = (Select B.E.DE.) * from where B = (SELECT MIN (B) to WHERE B> 10);   

See it live in any one.

No comments:

Post a Comment