MySQL:如何从double类型列中仅获取十进制值?

时间:2016-09-25 17:19:30

标签: mysql sql

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               |
+-------------------+

我怎样才能得到三个十进制数?

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

2 个答案:

答案 0 :(得分:1)

以下是cast的一个选项:

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

答案 1 :(得分:1)

这是使用% opertaor

的另一种方式
select *
from Youtable
where `number` % 1 <> 0