If your score columns contains data stored as varchar, you could convert those to decimal, using the CAST
function. For instance :
mysql> select cast('3.35643294332' as decimal(10,3));
+----------------------------------------+
| cast('3.35643294332' as decimal(10,3)) |
+----------------------------------------+
| 3.356 |
+----------------------------------------+
1 row in set (0,01 sec)
And note this will round the values correctly :
mysql> select cast('3.35663294332' as decimal(10,3));
+----------------------------------------+
| cast('3.35663294332' as decimal(10,3)) |
+----------------------------------------+
| 3.357 |
+----------------------------------------+
1 row in set (0,00 sec)
i.e. :
'3.3564'
was casted to 3.356
- and
'3.3566'
was casted to 3.357
Now, you only have to use that cast
function in your comparisons in your where
clause.
I suppose something like this should work, for instance :
select *
from your_table
where cast(Score as decimal(10,3)) = cast('3.4564' as decimal(10,3))
i.e., you convert both the "input" and Score to decimals with 3 decimals ; and you convert those values.
A a sidenote : doing so, you won't be using any index that you might have on Score, and will always end up with a full-scan... Which means another solution would be better... For instance, if you could use a where clause like score >= X and Score <= Y
, it would be much better...
But, as Score is stored as varchar, it won't be that easy, I suppose -- you should store those as decimals, btw...