sql 基础--mysql 5 (3)

8.计算字段

  concat () 拼接串

mysql> select concat (name,-,msg) from pw_luck;
+-----------------------+
| concat (name,-,msg) |
+-----------------------+
| Wilson-100            |
| zhangsan-100          |
| lisi-1001             |
| wang5-1001            |
| zhangsan7-1000        |
| zhangsan8-1000        |
| zhangsan9-1000        |
| wang5-1000            |
| wang5%-2000           |
| WANG5-1000            |
+-----------------------+
10 rows in set (0.00 sec)

  RTrim() 去掉右侧空格 LTrim() 去掉左侧空格 Trim() 去掉空格

  as 别名:

mysql> select concat (name,‘-‘,msg) as temp from pw_luck order by temp;
+----------------+
| temp |
+----------------+
| lisi-1001 |
| wang5%-2000 |
| WANG5-1000 |
| wang5-1000 |
| wang5-1001 |
| Wilson-100 |
| zhangsan-100 |
| zhangsan7-1000 |
| zhangsan8-1000 |
| zhangsan9-1000 |
+----------------+
10 rows in set (0.00 sec)

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。