Skip to content
Advertisement

Postgres how to return values in between Min column and Max column

totally new in learning postgres/SQL I have a table called error_table that looks like this:

but I am having a hard time generating a query on how to do this dynamically when my input number is 160, I would like to return the error_percent value 4.6 because 160 sits between the min column 100 and max column 200.

So far, here is what I am in my query

Now the problem is, I cannot use max <=160. How will I able to dynamically query the corresponding max value of returned min result and use it as my max <= returned max?

IF you have a better solution than mine, I appreciate the share.

Advertisement

Answer

Use a range comparison:

This assumes that your ranges are open on the minimum side and closed on the maximum side. If not, then the above range comparison would need to be changed.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement