Make MySQL Select Values Comparison

0

I have a table with four columns, the first with a type, the second with the minimum value, the third with the max value, and the fourth with the data that 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 this:

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 correct. If I try to change the 0.3 by 0.31, I get the desired result.

    
asked by anonymous 26.09.2014 / 19:22

3 answers

1

My table has the fields MAXIMO, MININO and TYPE in FLOAT type, and for comparison of the way I want, 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 made the exchange of the field to DECIMAL (4.2), where the comparison occurs efficiently.

    
26.09.2014 / 20:02
1
SELECT VALOR FROM TABELA WHERE ((TIPO = 1) AND (0.3 BETWEEN MINIMO AND MAXIMO))
    
26.09.2014 / 20:13
1

Try to use the between command.

Example:

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
    
26.09.2014 / 19:51