So, having these rows on table
## raw_material_costs ##
id code family material min_size max_size value
651 100005 sleeve SAE 1020 1.21 1.24 4.48882
659 100006 sleeve SAE 1020 1.21 1.24 6.62878
Running the following query directly on the SQL tab doesn't return any of these rows. I want to get the row if the value (in this case is 1.21) is equal to min_size
or is between min_size
and max_size
. (Tried to use the BETWEEN comparison before and got the same result)
SELECT * FROM (`raw_material_costs`)
WHERE `raw_material_costs`.`family` = 'sleeve'
AND `raw_material_costs`.`material` = 'SAE 1020'
AND (
( `raw_material_costs`.`min_size` = '1.21' )
OR ( `raw_material_costs`.`min_size` >= '1.21' AND `raw_material_costs`.`max_size` <= '1.21' )
)
EDIT1: Forgot to mention the value used.
Fixed query (solution pointed by cjg[look below])
SELECT *
FROM (`raw_material_costs`)
WHERE `raw_material_costs`.`family` = 'sleeve'
AND
`raw_material_costs`.`material` = 'SAE 1020'
AND (
(
CAST( `min_size` as DECIMAL(10,2) ) =
1.21
)
OR (
CAST( `min_size` as DECIMAL(10,2) ) >= '1.21'
AND CAST( `max_size` as
DECIMAL(10,2) ) <= '1.21'
)
)