MySQL创建计算字段concat、trim

阅读更多
1. 计算字段

计算字段

拼接字段
SQL> select concat(vend_name, '(', vend_country, ')') from vendors order by vend_name;

去空格
SQL> select concat(rtrim(vend_name), '(', rtrim(vend_country), ')') from vendors order by vend_name;

使用别名
SQL> select concat(rtrim(vend_name), '(', rtrim(vend_country), ')') as vend_title from vendors order by vend_name;

执行算术计算
SQL> select prod_id, quantity, item_price, quantity*item_price as expanded_price from orderitems where order_num = 20005;

1. concat(a, b, c...) 拼接多个字段
2. rtrim() 函数去掉值右边的所有空格
   ltrim() 函数去掉值左边的所有空格
    ()  函数去掉值两边的空格
3. old as new 别名用AS关键值赋值
4. a*b as result 计算算术,也可以直接查询
    select 2*3; 返回6
    select trim(' abc '); 返回abc

你可能感兴趣的:(mysql)