Answer the question
In order to leave comments, you need to log in
Postgres closest number?
There is a table - the ratio.
That is, for 0.5 - 3
For 1.0 - 5.4
The dependence is empirical (ie calculated in real conditions). The formula does not describe.
Table step - 0.5
How, depending on what the user entered, to pull out the corresponding number?
Smartly, you need to calculate according to the formula
y = ((x - x1) / (x2 - x1)) * (y2 - y1) + y1;
Answer the question
In order to leave comments, you need to log in
select * from (
select t.*, abs(value - 1.1) as diff
from t
order by diff asc
limit 2
) x
order by value
sort by minimum difference and take the first value...
SELECT ...
FROM ...
ORDER @ x-1.3 ASC
LIMIT 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question