当前位置:网站首页>【MySQL】查询多个ID返回字符串拼接
【MySQL】查询多个ID返回字符串拼接
2022-07-28 09:34:00 【51CTO】
MySQL中concat函数
使用方法:
concat(str1,str2,…)
返回结果为连接参数产生的字符串。如有任何一个参数为NULL ,则返回值为 NULL。
MySQL的concat函数在连接字符串的时候,只要其中一个是NULL,那么将返回NULL
MySQL中concat_ws函数
使用方法:
contcat_ws(separator,str1,str2,...)
contcat_ws() 代表 CONCAT With Separator ,是CONCAT()的特殊形式。第一个参数是其它参数的分隔符。分隔符的位置放在要连接的两个字符串之间。分隔符可以是一个字符串,也可以是其它参数。
注意:
如果分隔符为 NULL,则结果为 NULL。函数会忽略任何分隔符参数后的 NULL 值。如连接后以逗号分隔
和MySQL中concat函数不同的是, concat_ws函数在执行的时候,不会因为NULL值而返回NULL
MySQL中group_concat函数
完整的语法如下:
group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])
基本查询
以id分组,把name字段的值打印在一行,逗号分隔(默认)
以id分组,把name字段的值打印在一行,分号分隔
以id分组,把去冗余的name字段的值打印在一行,
逗号分隔
以id分组,把name字段的值打印在一行,逗号分隔,以name排倒序
mysql> select id,group_concat(name order by name desc) from aa group by id;
MySQL中repeat()函数
用来复制字符串,如下'ab'表示要复制的字符串,2表示复制的份数
又如
边栏推荐
猜你喜欢

Introduction to SD card (based on spec3.0)

Opencv4.60 installation and configuration

Net 3 lines of code to realize the function of text to speech

Real time editor of MATLAB

2022-7-27周报

Pycharm uses CONDA to call the remote server

Standing on the shoulders of big men, you can see further

MySQL master-slave architecture. After the master database is suspended and restarted, how can the slave database automatically connect to the master database

Linux操作系统(Centos7)安装MySQL

关于CLR GC调优的一些问题
随机推荐
Take you to wechat applet development in 3 minutes
Array collation commonly used in PHP
领域事件和集成事件没那么高大上
Sequence and limit operation of MATLAB
In php7?? And?: Differences between
Plato Farm-以柏拉图为目标的农场元宇宙游戏
Window source code analysis (III): window update mechanism
How to learn so many conceptual things in database? Seeking method
Learn a hammer.Net zero foundation reverse tutorial lesson 3 (shell and homework)
Basic operation of MATLAB
今天和大家聊一聊mysql数据库的数据类型
Retrofit源码解析
Opencv4.60 installation and configuration
Some problems about CLR GC tuning
Judge whether the string is palindrome
MQ learning
这款微信插件太好用了
Edge团队详解如何通过磁盘缓存压缩技术提升综合性能体验
C# 倒计时工具
设计一个支持百万用户的系统