Compare Mysql Select Values

Asked

Viewed 2,134 times

0

I have a table with four columns, the first with one type, the second with the minimum value , the third with the max value, and the fourth with the data I want. I need to select the value of the fourth column when the type is in the table and the value entered is between the maximum and minimum value, I tried to do as follows:

SELECT VALOR FROM TABELA WHERE TIPO = 1 AND MINIMO <=0.3 AND MAXIMO >= 0.3;

TIPO    MINIMO  MAXIMO  VALOR
1       0       0,15    0
1       0,2     0,29    8,1
1       0,3     0,54    7,97
1       0,55    5       7,42

For the table above, the value should be 7.97, but not the right one. If I try to exchange 0.3 for 0.31, I get the desired result.

  • I simulated your data and there was no problem... Sqlfiddle

3 answers

1


My table is with the fields MAXIMO, MININO and TYPE in the type FLOAT, and for comparison of the way I wish, this format is not interesting, according to the link Problems with Float type . The solution was simple, as these values must have 4 digits, being 2 decimals, I changed the field to DECIMAL(4,2), where the comparison occurs efficiently.

1

SELECT VALOR FROM TABELA WHERE ((TIPO = 1) AND (0.3 BETWEEN MINIMO AND MAXIMO))

1

Try using the command between.

Example:

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
  • Thanks for the answer, but the problem persists.

Browser other questions tagged

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