concat、concat_ws、group_concat都可以用来连接字符串。

concat和concat_ws用来连接同一行中不同列的数据,group_ws用来连接同一列的数据。

格式如下:

  • concat(str1, str2, ...)
  • concat_ws(separator, str1, str2, ...)
  • group_concat([distinct] 列名  [order by 列名 desc/asc] [separator 分隔符])

group_concat一般和group by 子句配合使用,将group by 产生的同一分组中的值连接起来,返回一个字符串结果。

  • select name, group_concat(id) from tb1 group by name   -- 将相同name的所有id连接起来
  • select name, group_concat(id order by id desc separator  '-' ) from tb1 group by name   -- 将相同name的所有id连接起来,并降序排序,连接符为-
  • select name, group_concat(concat_ws('-', id, score)) from tb1 group by name  -- 将相同name的所有id和score连接起来

mysql之concat concat_ws group_concat的更多相关文章

  1. mysql中的concat,concat_ws(),group_concat()

    mysql中的concat,concat_ws(),group_concat() 说明: 本文中使用的例子均在下面的数据库表tt2下执行:     一.concat()函数 1.功能:将多个字符串连接 ...

  2. mysql函数concat与group_concat使用说明

    mysql函数concat与group_concat使用说明concat()函数<pre>mysql> select concat(',',name,',') from `user` ...

  3. MySQL中的字段拼接 concat() concat_ws() group_concat()函数

    1.concat()函数 2.concat_ws()函数 3.group_concat()函数 操作的table select * from test_concat order by id limit ...

  4. 浅析MySQL中concat以及group_concat的使用

      说明: 本文中使用的例子均在下面的数据库表tt2下执行: 一.concat()函数 1.功能:将多个字符串连接成一个字符串. 2.语法:concat(str1, str2,...) 返回结果为连接 ...

  5. mysql中concat 和 group_concat()的用法

    一.CONCAT()函数CONCAT()函数用于将多个字符串连接成一个字符串.使用数据表Info作为示例,其中SELECT id,name FROM info LIMIT 1;的返回结果为+----+ ...

  6. sql优化之concat/concat_ws/group_concat

    原文1:https://baijiahao.baidu.com/s?id=1595349117525189591&wfr=spider&for=pc 原文2:https://www.y ...

  7. MySQL之concat以及group_concat的用法

    本文中使用的例子均在下面的数据库表tt2下执行: 一.concat()函数 1.功能:将多个字符串连接成一个字符串. 2.语法:concat(str1, str2,...) 返回结果为连接参数产生的字 ...

  8. MySQL的concat以及group_concat的用法

    一.concat()函数 1.功能:将多个字符串连接成一个字符串. 2.语法:concat(str1, str2,...) 返回结果为连接参数产生的字符串,如果有任何一个参数为null,则返回值为nu ...

  9. MySQL中concat以及group_concat的使用

    摘自:https://www.jianshu.com/p/43cb4c5d33c1 说明: 本文中使用的例子均在下面的数据库表tt2下执行: 一.concat()函数 1.功能:将多个字符串连接成一个 ...

随机推荐

  1. B. Creating the Contest(水题)

    直接水过 #include<iostream> #include<algorithm> using namespace std; ; int a[maxn]; int n, u ...

  2. 20145203盖泽双《网络对抗技术》拓展:注入:shellcode及return-into-libc攻击

    20145203盖泽双<网络对抗技术>拓展:注入:shellcode及return-into-libc攻击 一.注入:shellcode 1.编写一段用于获取Shellcode的C语言代码 ...

  3. day16--包的认识、循环导入、绝对导入、相对导入、模块的搜索路径等(待续)

    ''' 一系列功能模块的集合体 -- 包就是管理功能相近的一系列模块的文件夹 -- 该文件夹包含一个特殊文件__init__.py -- 文件夹名就是包名,产生的包名就是指向__init__.py的全 ...

  4. Maven的继承以及import作用域

    Maven的pom文件中可继承的元素包括: groupId:项目ID,项目坐标核心元素 version:项目版本 description:描述信息 organization:组织信息 inceptio ...

  5. Selenium自动化测试之学会元素定位

    这是我经常被问到的一个问题,也是我很讨厌回答的问题,因为要想回答这个问题需要知道上下文.什么样式的元素,有哪些属性,是否有表单嵌套,都尝试了哪些定位方法...而且没几个提问者能事先详细的说明这些.哪儿 ...

  6. 《通过C#学Proto.Actor模型》之Supervision

    Supervision,字面意思是监督,是父Actor发现子Actor有异常发生后,对子Actor产用保种策略处理的机制,如果父Actor不处理,则往上传递. 子Actor发生异常后处理的策略有: R ...

  7. Scrapy中选择器的用法

    官方文档:https://doc.scrapy.org/en/latest/topics/selectors.html Using selectors Constructing selectors R ...

  8. jQuery实现单击某个标签改变样式

    1.HTML代码,如下图: <p class="sc_member_recharge_form"> <span class="selected" ...

  9. CRM专业术语

    客户关系管理(管理学词汇CRM)_百度百科https://baike.baidu.com/item/%E5%AE%A2%E6%88%B7%E5%85%B3%E7%B3%BB%E7%AE%A1%E7%9 ...

  10. spring异常Unsatisfied dependency expressed through constructor parameter 0

    异常信息: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with nam ...