Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Only the Fractional Part of a Number's value

Tags:

How do I select only the part of the value of a number to the right of the decimal point?

So for example:

SELECT ____(10.1234) AS mynumber; 

Where the result would be:

.1234 (or 1234) 
like image 744
jkdoyle Avatar asked Nov 18 '14 19:11

jkdoyle


2 Answers

The MOD function should work:

SELECT MOD(10.1234, 1); -- -> 0.1234 
like image 151
Tom Avatar answered Oct 27 '22 05:10

Tom


You can also use below...

select substring_index(field1,'.',1), substring_index(field1,'.',-1) from table1; 

Sample output

mysql> select substring_index(120.45,'.',1), substring_index(120.45,'.',-1) ; +-------------------------------+--------------------------------+ | substring_index(120.45,'.',1) | substring_index(120.45,'.',-1) | +-------------------------------+--------------------------------+ | 120                           | 45                             | +-------------------------------+--------------------------------+ 1 row in set (0.00 sec) 
like image 39
Phaneendra Avatar answered Oct 27 '22 05:10

Phaneendra