拼接字段
mysql> SELECT Concat(vend_name,'(',vend_country,')')
FROM vendors
ORDER BY vend_name;
+----------------------------------------+
| Concat(vend_name,'(',vend_country,')') |
+----------------------------------------+
| ACME(USA) |
| Anvils R Us(USA) |
| Furball Inc.(USA) |
| Jet Set(England) |
| Jouets Et Ours(France) |
| LT Supplies(USA) |
+----------------------------------------+
6 rows in set (0.00 sec)
- Concat() 拼接串,即把多个串连接起来形成一个较长的串;
- Concat()需要一个或多个指定的串,各个串之间用逗号分隔。
RTrim() / LTrim() / Trim()
- RTrim()函数用于去掉右边的所有空格;
- LTrim()函数用于去掉左边的所有空格;
- Trim()函数用于去掉两边的所有空格。
使用别名
mysql> SELECT Concat(vend_name,'(',vend_country,')')
FROM vendors
ORDER BY vend_name;
+----------------------------------------+
| Concat(vend_name,'(',vend_country,')') |
+----------------------------------------+
| ACME(USA) |
| Anvils R Us(USA) |
| Furball Inc.(USA) |
| Jet Set(England) |
| Jouets Et Ours(France) |
| LT Supplies(USA) |
+----------------------------------------+
6 rows in set (0.00 sec)
执行算术计算
mysql> SELECT prod_id,quantity,item_price,quantity*item_price
AS expanded_price
FROM orderitems
WHERE order_num=20005;
+---------+----------+------------+----------------+
| prod_id | quantity | item_price | expanded_price |
+---------+----------+------------+----------------+
| ANV01 | 10 | 5.99 | 59.90 |
| ANV02 | 3 | 9.99 | 29.97 |
| TNT2 | 5 | 10.00 | 50.00 |
| FB | 1 | 10.00 | 10.00 |
+---------+----------+------------+----------------+
4 rows in set (0.00 sec)