选择在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 出阁宴祝福语姐姐简短