How to select to find a record between two values?

Asked

Viewed 196 times

0

I have a table with the following values

#   valor_min  vlr_max  juros
1    0         1999         0
2    2000      2999       1.2  
3    3000      3999       1.3
4    4000      999999     1.4

I need to consult this table with the value ex.: 2500,00 find the corresponding interest, in this case it would be line 2.

How would select in this case?

3 answers

2


I believe the query below meets:

SELECT juros FROM sua_tabela WHERE 2500 BETWEEN valor_min AND valor_max;
  • The goal is to scroll through the table to find lines that best satisfy the value.

  • Thank you very much, solved my doubt

1

Well, your query would be something like this:

SELECT juros FROM [tabela] where valor_min BETWEEN valor_min AND 2500 AND valor_max BETWEEN 2500 AND valor_max

However, when I published I saw a query presented, more elegant, and simpler.

SELECT juros FROM sua_tabela WHERE 2500 BETWEEN valor_min AND valor_max
  • Thank you, but as you said had already posted. Thank you so much.

0

Select * from sua_tabela where 2500 >= valor_min and 2500 <= valor_max

Browser other questions tagged

You are not signed in. Login or sign up in order to post.