MySQL常用命令(五)-Concat、Trim

字段拼接-Concat()函数

作用:将多个串拼接成一个长串,各个待拼接的串之间以逗号隔开;
格式:Concat('串1','串2','串3');

mysql> SELECT CONCAT(name,'_',salary) AS info FROM person;
+--------------+
| info         |
+--------------+
| Jack_5600.00 |
| Mary_3000.00 |
| jhon_7000.00 |
| Mary_8000.00 |
| Mary_1000.00 |
| Ken_9000.00  |
| Ken_9000.00  |
+--------------+
7 rows in set (0.00 sec)

mysql> SELECT name,salary FROM person;
+------+---------+
| name | salary  |
+------+---------+
| Jack | 5600.00 |
| Mary | 3000.00 |
| jhon | 7000.00 |
| Mary | 8000.00 |
| Mary | 1000.00 |
| Ken  | 9000.00 |
| Ken  | 9000.00 |
+------+---------+
7 rows in set (0.00 sec)

mysql> 

算术运算符

作用:支持+、-、*、/运算,()的优先级更高;

mysql> SELECT productName,price,num FROM product;
+-------------+---------+-----+
| productName | price   | num |
+-------------+---------+-----+
| 10001       |  100.00 |   1 |
| 10001       |  450.00 |   3 |
| 10002       |   30.00 |   4 |
| 10002       |  888.00 |   6 |
| 10003       | 1000.00 |   1 |
+-------------+---------+-----+
5 rows in set (0.00 sec)

mysql> SELECT productName,(price*num) AS total FROM product;
+-------------+---------+
| productName | total   |
+-------------+---------+
| 10001       |  100.00 |
| 10001       | 1350.00 |
| 10002       |  120.00 |
| 10002       | 5328.00 |
| 10003       | 1000.00 |
+-------------+---------+
5 rows in set (0.00 sec)

Trim

作用:去除空格
类似的有:RTrim()、LTrim()

mysql> SELECT Trim('  abc   ');
+------------------+
| Trim('  abc   ') |
+------------------+
| abc              |
+------------------+
1 row in set (0.00 sec)

mysql> SELECT RTrim('  abc   ');
+-------------------+
| RTrim('  abc   ') |
+-------------------+
|   abc             |
+-------------------+
1 row in set (0.00 sec)

mysql> SELECT LTrim('  abc   ');
+-------------------+
| LTrim('  abc   ') |
+-------------------+
| abc               |
+-------------------+
1 row in set (0.00 sec)

你可能感兴趣的:(MySQL常用命令(五)-Concat、Trim)