赞
踩
concat()
concat(str1,str2,str3,…)
连接参数的函数,返回结果为连接参数的字符串。如果有一个参数为NULL
,则返回的结果为NULL
。
concat('a', 'b', 'c') ---- 'abc'
concat('a', null, 'c')----null
concat_ws()
concat_ws('分隔符', str1, str2, …)
concat()
的一个特殊形式,表示concat with separator
,两个参数之间加上特定的分隔符。返回的是用指定分隔符连接参数的字符串。如果分割符为null
,则返回null
,参数为null
,则忽略该参数。
concat_ws("/", "2018", "12", "19")----2018/12/19
concat_ws(":", "22", "47", null)----22:47
concat_ws(null, "22", "47")----null
group_concat()
group_concat(str1, [order by str3], [separator '分隔符'])
把相同组的字符串以特定分隔符连接为一行。
id | name |
1 | bob |
1 | anna |
1 | helen |
2 | tom |
2 | baby |
2 | tom |
id
分组,把name
连接为1行select id, group_concat(name)
1 | bobannahelen |
2 | tombabytom |
id
分组,把name
连接为一行,并按name
升序select id,group_concat(name order by name asc)
1 | annabobhelen |
2 | babytomtom |
id
分组,name
去重并连接为一行,按name
升序,用逗号分隔select id,group_concat(name order by name asc)
1 | anna,bob,helen |
2 | baby,tom |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。