mysql属性拼接函数

1,concat 多个字段拼接 。

如: select concat(‘1’,‘2’,‘3’) from test ; 结果 : 123

select concat(content_title,"|",content_price) from contents ;  

2,concat_ws(separator,str1,str2,…) 多个字段拼接,第一个参数是其它参数的分隔符

如:select concat_ws(’:’,‘1’,‘2’,‘3’) from test ; 结果:1:2:3

select concat_ws("|",content_title,content_price,speaker) from contents ;  

3,group_concat 多行结果拼接

select group_concat(column_name) 
from information_schema.columns 
where table_schema='exchange' and table_name='bf_dd';

其他函数

substring 截取字符串 :

substring(str, pos) 说明:substring(被截取字段,从第几位开始截取)

substring(str, pos, length) substring(被截取字段,从第几位开始截取,截取长度)

select substring(content,5) as abstract from my_content_t 
select substring(content,5,200) as abstract from my_content_t 

猜你喜欢

转载自blog.csdn.net/fangye1/article/details/110952754