《MySQL必知必会》第十章:创建计算字段
@author: Tobin
@date: 2019/10/28 19:51:40
字段field和列的意思相同,对列的数据进行处理转换成客户机需要的形式。
# 拼接 MySQL用Concat()函数,多数DBM用+和||来实现拼接
SELECT Concat(vend_name, '(', vend_country,')')
FROM vendors
ORDER BY vend_name;
# Trim()函数,去除空格。LTrim(),RTrim()。
SELECT Concat(RTrim(vend_name), '(', RTrim(vend_country),')')
FROM vendors
ORDER BY vend_name;
# 使用别名,拼接完成的数据存到一个新列上,又称为导出列
SELECT Concat(RTrim(vend_name), '(', RTrim(vend_country),')') AS
vend_title
FROM vendors
ORDER BY vend_name;
# + - * \
SELECT prod_id, quantity, item_price, quantity*item_price AS
expanded_price
FROM orderitems
WHERE order_num = 20005;