选择在MySQL中具有多于2个小数位的行?
要选择小数点后2位以上的行,请使用SUBSTR()MySQL中的function。让我们首先创建一个表-
mysql> create table selectRows2DecimalPlacesDemo -> ( -> Amount varchar(100) -> );
以下是使用insert命令在表中插入记录的查询-
mysql> insert into selectRows2DecimalPlacesDemo values('234.5678');
mysql> insert into selectRows2DecimalPlacesDemo values('19.50');
mysql> insert into selectRows2DecimalPlacesDemo values('23.456');
mysql> insert into selectRows2DecimalPlacesDemo values('12.123');以下是使用select语句显示表中所有记录的查询-
mysql> select * from selectRows2DecimalPlacesDemo;
这将产生以下输出-
+----------+ | Amount | +----------+ | 234.5678 | | 19.50 | | 23.456 | | 12.123 | +----------+ 4 rows in set (0.00 sec)
这是选择多于两个小数位的行的查询-
mysql> select *from selectRows2DecimalPlacesDemo WHERE LENGTH(SUBSTR(Amount,INSTR(Amount,"."))) >3;
这将产生以下输出-
+----------+ | Amount | +----------+ | 234.5678 | | 23.456 | | 12.123 | +----------+ 3 rows in set (0.00 sec)
热门推荐
10 许愿星姐妹祝福语简短
11 发小结婚简短祝福语
12 嫂子生日的祝福语简短
13 高温祝福语短语大全简短
14 新娘上头祝福语大全简短
15 打牌翻盘祝福语简短
16 冬至婆婆的祝福语简短
17 祝美术老师祝福语简短
18 妹妹生日祝福语简短唯美