当前位置:网站首页>【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表示复制的份数
又如
边栏推荐
- C form application uses object binding DataGridView data binding
- 这种动态规划你见过吗——状态机动态规划之股票问题(中)
- 软件测试与质量学习笔记1---黑盒测试
- Source code analysis of view event distribution mechanism
- 业务可视化-让你的流程图'Run'起来(4.实际业务场景测试)
- Time series analysis 41 - time series prediction tbats model
- Install lamp under deepin
- Detailed explanation of various types of files in MySQL
- Business visualization - make your flowchart'run'(4. Actual business scenario test)
- The high temperature continues, and public transport enterprises carry out special safety training
猜你喜欢

软件测试与质量学习笔记1---黑盒测试

Seeing clearly is more important than walking fast, because you can go far only when you walk right

Opencv installation configuration test

OSS direct upload rails service practice

Go language slice vs array panic runtime error index out of range problem solving

Real time editor of MATLAB

【日志】日志干什么的?日志工厂是什么?log4j 的配置和使用? log4j.properties 文件配置、log4j jar包坐标

高温持续,公交企业开展安全专项培训

TCP 基础知识

Plato Farm-以柏拉图为目标的农场元宇宙游戏
随机推荐
设计一个支持百万用户的系统
Analysis of the internal principle of LinkedList
JS提升:实现flat平铺的底层原理
MATLAB启动慢解决措施
备受关注的Bit.Store,最新动态一览
Mobile number, fixed line regular expression
数据库高级学习笔记--系统包
Software testing and quality learning notes 2 - black box testing
OSS直连上传-Rails服务实践
Judge whether the string is palindrome
With such a simple verification, 80% of programmers can't do it, let alone understand it!
如何使用JWT进行身份验证与授权
数据不会说谎,Plato Farm就是元宇宙龙头
SeekTiger生态通证STI 新进展,4月14日登录 ZB
时序分析41 - 时序预测 TBATS模型
View事件分发机制源码解析
The high temperature continues, and public transport enterprises carry out special safety training
PHP连接mysql原生代码
Window源码解析(四):Window的删除机制
Deepin 下安装 LAMP