mysql基础③mian表

有如下表和数据,查出num>=20 and num<=39的数字,并且,把num值处于20到29之间的,显示为20。 num值处于30到39之间的,显示为30

mian表
+------+
| num  |
+------+
|    3 |
|   12 |
|   15 |
|   25 |
|   23 |
|   29 |
|   34 |
|   37 |
|   32 |
|   45 |
|   48 |
|   52 |
+------+
思路:先查出20到39的数字然后除以10得到浮点数,用浮点数取整数的四舍五入函数取整,然后在乘以10得到整数20和30,用update修改表里数据 ,在查询出来。 四舍五入函数(http://www.phperz.com/article/14/0720/12681.html)
查询20到39的数字
select num from mian where
得到的数字除以10
select (num/10),num from mian
用floor函数取整在乘以10
select floor(num/10)*10,num from mian
修改表里num的值
update mian set num=floor(num/10)*10 where num between 20 and 39;
查询出表里的值
select num from mian;

原文地址:https://www.cnblogs.com/ctx1989/p/5910446.html