What about using the LIKE
clause in MySQL?
SELECT * FROM table WHERE priority LIKE %.2%
Question
Using the MySQL command prompt, I want to SELECT all rows conataining a specific fractional part of number.
I have a field of type FLOAT called priority & I want to find all rows where the priority is X.2 where X can be any whole number.
Is there a way to use the MOD or FLOOR function to extract the ".2" in a query?
I've tried:
SELECT * from table
WHERE priority-FLOOR(priority) = .2 *(note the decimal point before the 2)*
but it returns empty set when I know there are at least 100 rows containing a priority of X.2
Thanks
Solution
What about using the LIKE
clause in MySQL?
SELECT * FROM table WHERE priority LIKE %.2%
OTHER TIPS
Floating point numbers are notoriously fickle to work with. That is why SQL offers the decimal
data type, which is fixed length.
Do what you want with between:
SELECT *
from table
WHERE priority-FLOOR(priority) between 0.15 and 0.25
Consider storing the priority as a decimal instead of a floating point number.
If you have "deeper" priorities, like 1.22 that you are trying to avoid, then do:
WHERE priority-FLOOR(priority) between 0.195 and 0.205
The range can be even narrower, if you need.