zono
zono

Reputation: 8584

MySQL: How can I get only decimal value from double type column?

CREATE TABLE `sample` (
  `number` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


mysql> select * from sample
+-------------------+
| number            |
+-------------------+
| 1                 |
| 2                 |
| 3.5               |
| 4.5               |
| 0.1               |
+-------------------+

How can I get only the three decimal numbers?

+-------------------+
| number            |
+-------------------+
| 3.5               |
| 4.5               |
| 0.1               |
+-------------------+

Upvotes: 0

Views: 910

Answers (3)

vasim shah
vasim shah

Reputation: 1

solution:

SELECT * FROM sample where number like '%.%';

Upvotes: 0

Pரதீப்
Pரதீப்

Reputation: 93754

Here is a another way using % opertaor

select *
from Youtable
where `number` % 1 <> 0

Upvotes: 1

sgeddes
sgeddes

Reputation: 62861

Here's one option with cast:

select * 
from sample
where cast(number as unsigned) <> number

Upvotes: 2

Related Questions