G
G
GLaDosSystem2019-06-01 20:29:27
PostgreSQL
GLaDosSystem, 2019-06-01 20:29:27

How to get the closest value that is less than a given one?

There is a table with numbers. The table is sorted in ascending order of these numbers. How can I find a table row with a number closest to a given number (let's say 100) but less than it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentin V., 2019-06-01
@GLaDosSystem

A separate row with the closest value to the specified one can be obtained like this

SELECT *
  FROM my_numbers
 WHERE my_num < 100
 ORDER BY my_num desc
 LIMIT 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question