Search for value corresponding to weight

2

I have a table with values, where each value is according to weight (kg).

  

Up to 3kg = $ 20.00

     

Up to 5kg = $ 25.00

     

Up to 10kg = $ 28.00

SELECT estado, kg, valorCap, valorExcedCap, valorAloremCap, prazoCap 
  FROM transportadoras_valores 
    WHERE id_transportadora = '1' && estado = 'AL' && kg = '4'

In this example I need to return the value of 5kg.

I have an online example:

link

    
asked by anonymous 14.05.2015 / 21:49

3 answers

5

You can do this:

SELECT estado, kg, valorCap, valorExcedCap, valorAloremCap, prazoCap 
  FROM transportadoras_valores 
  WHERE id_transportadora = 1 && estado = 'AL' && kg >= 4
  ORDER BY kg ASC
  LIMIT 1

In this way you say that you want it to be a single result, the first one to be greater than or equal to the value you passed the query.

    
14.05.2015 / 21:54
-1
SELECT estado, kg, valorCap, valorExcedCap, valorAloremCap, prazoCap
    FROM transportadoras_valores 
    WHERE id_transportadora = '1' && estado = 'AL' && kg = '5'
    
14.05.2015 / 21:58
-1
SELECT estado, kg, valorCap, valorExcedCap, valorAloremCap, prazoCap 
FROM transportadoras_valores 
WHERE id_transportadora = '1' && estado = 'AL' && kg > '3' && kg <= '5')
    
14.05.2015 / 21:52