比如
字段1
fafas
fasdfd
fagwewfwe
geqfds
比如只保留后面三个字符
得到
字段1
fas
dfd
fwe
fds
怎么写?》
10 个解决方案
#1
RIGHT(str,len)
从字符串str 开始,返回最右len 字符。
从字符串str 开始,返回最右len 字符。
#2
select right(字段名,3) from 表名;
#3
update yourTable set 字段1=right(字段名,3);
#4
左面用left(,3);
右面用right();
右面用right();
#5
update tb
set col=right(rtrim(col),3)
#6
mysql> select right('fagwewfwe',3);
+----------------------+
| right('fagwewfwe',3) |
+----------------------+
| fwe |
+----------------------+
1 row in set (0.00 sec)
mysql> select right('geqfds',3);
+-------------------+
| right('geqfds',3) |
+-------------------+
| fds |
+-------------------+
1 row in set (0.00 sec)
mysql>
+----------------------+
| right('fagwewfwe',3) |
+----------------------+
| fwe |
+----------------------+
1 row in set (0.00 sec)
mysql> select right('geqfds',3);
+-------------------+
| right('geqfds',3) |
+-------------------+
| fds |
+-------------------+
1 row in set (0.00 sec)
mysql>
#7
select right(字段名,要取的长度) from 表名
#8
RIGHT(char_expr,integer_expler)
换回字符串从右开始到指定位置的部分字符;
换回字符串从右开始到指定位置的部分字符;
#9
mysql> select right("asdfasfsafas",3);
+-------------------------+
| right("asdfasfsafas",3) |
+-------------------------+
| fas |
+-------------------------+
1 row in set (0.00 sec)
mysql> select left("asdfasfsafas",3);
+------------------------+
| left("asdfasfsafas",3) |
+------------------------+
| asd |
+------------------------+
1 row in set (0.00 sec)
mysql> select substring("asdfasfsafas",length('asdfasfsafas')-2,3);
+------------------------------------------------------+
| substring("asdfasfsafas",length('asdfasfsafas')-2,3) |
+------------------------------------------------------+
| fas |
+------------------------------------------------------+
1 row in set (0.00 sec)
#10
用right函数即可:
mysql> select right ('abcdefg',3) as a;
+------+
| a |
+------+
| efg |
+------+
1 row in set (0.02 sec)
mysql>
#1
RIGHT(str,len)
从字符串str 开始,返回最右len 字符。
从字符串str 开始,返回最右len 字符。
#2
select right(字段名,3) from 表名;
#3
update yourTable set 字段1=right(字段名,3);
#4
左面用left(,3);
右面用right();
右面用right();
#5
update tb
set col=right(rtrim(col),3)
#6
mysql> select right('fagwewfwe',3);
+----------------------+
| right('fagwewfwe',3) |
+----------------------+
| fwe |
+----------------------+
1 row in set (0.00 sec)
mysql> select right('geqfds',3);
+-------------------+
| right('geqfds',3) |
+-------------------+
| fds |
+-------------------+
1 row in set (0.00 sec)
mysql>
+----------------------+
| right('fagwewfwe',3) |
+----------------------+
| fwe |
+----------------------+
1 row in set (0.00 sec)
mysql> select right('geqfds',3);
+-------------------+
| right('geqfds',3) |
+-------------------+
| fds |
+-------------------+
1 row in set (0.00 sec)
mysql>
#7
select right(字段名,要取的长度) from 表名
#8
RIGHT(char_expr,integer_expler)
换回字符串从右开始到指定位置的部分字符;
换回字符串从右开始到指定位置的部分字符;
#9
mysql> select right("asdfasfsafas",3);
+-------------------------+
| right("asdfasfsafas",3) |
+-------------------------+
| fas |
+-------------------------+
1 row in set (0.00 sec)
mysql> select left("asdfasfsafas",3);
+------------------------+
| left("asdfasfsafas",3) |
+------------------------+
| asd |
+------------------------+
1 row in set (0.00 sec)
mysql> select substring("asdfasfsafas",length('asdfasfsafas')-2,3);
+------------------------------------------------------+
| substring("asdfasfsafas",length('asdfasfsafas')-2,3) |
+------------------------------------------------------+
| fas |
+------------------------------------------------------+
1 row in set (0.00 sec)
#10
用right函数即可:
mysql> select right ('abcdefg',3) as a;
+------+
| a |
+------+
| efg |
+------+
1 row in set (0.02 sec)
mysql>