mysql函数concat与group_concat使用说明详解数据库
2023-06-13 09:20:09 时间
mysql函数concat与group_concat使用说明
concat()函数
mysql select concat(,,name,,) from `user`;
+--------------------------+
| concat(,,fdipzone,,) |
+--------------------------+
| ,fdipzone, |
+--------------------------+
1 row in set (0.00 sec)
concat_ws() 函数
mysql select concat_ws(,,country_code,phone,region) from `user`;
+------------------------------------------+
| concat_ws(,,country_code,phone,region) |
+------------------------------------------+
| 86,13794830550,GZ |
+------------------------------------------+
1 row in set (0.00 sec)
group_concat()函数
mysql select * from `article_in_category`;
+----+------------+-------------+
| id | article_id | category_id |
+----+------------+-------------+
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 1 | 3 |
| 4 | 2 | 4 |
| 5 | 2 | 3 |
| 6 | 2 | 5 |
| 7 | 3 | 1 |
| 8 | 3 | 5 |
| 9 | 3 | 6 |
| 10 | 4 | 8 |
+----+------------+-------------+
mysql select article_id,group_concat(category_id order by category_id asc) from `article_in_category` group by article_id;
+------------+----------------------------------------------------+
| article_id | group_concat(category_id order by category_id asc) |
+------------+----------------------------------------------------+
| 1 | 1,2,3 |
| 2 | 3,4,5 |
| 3 | 1,5,6 |
| 4 | 8 |
+------------+----------------------------------------------------+
4 rows in set (0.00 sec)
ps:category_id order by category_id asc 这个是 字段里面的的排序 比方说1,2,3就是升序啦
注意:group_concat()函数对返回的结果有长度限制,默认为1024字节
mysql set global group_concat_max_len=2048;
Query OK, 0 rows affected (0.03 sec)mysql show global variables like %group_concat_max_len%;
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| group_concat_max_len | 2048 |
+----------------------+-------+
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/4047.html
mysql相关文章
- MySQL测试:探索基于SQL语句的可能性(mysql测试语句)
- MySQL字符串切割技巧探索(mysql的字符串切割)
- MySQL内连接:有效获取数据的技术(mysql内连接)
- MySQL数据库在网页开发中的应用(网页mysql数据库)
- MySQL存储过程实现条件判断及其应用(mysql存储过程判断)
- :MySQL数据库:简单实用的数据处理方式(mysql数据库例子)
- 存储MySQL:通过二进制存储数据实现最佳性能(mysql二进制数据)
- C语言中的MySQL数据库研究简介(c中mysql数据库)
- 【深入探索:MySQL数据库文件之旅】(查看mysql数据库文件)
- 探究MySQL数据库中各种数据类型(mysql数据库中的类型)
- MySQL实现跨多个数据库同步(mysql同步多个数据库)
- 一步步教你清空MySQL数据库(mysql清空数据库命令)
- 称查询MySQL:查询当前数据库名称的方法(mysql 当前数据库名)
- MySQL如何快速导出数据库(mysql 导出 数据库)
- 新建MySQL数据库:一步步创建过程(新建 mysql 数据库)
- MySQL数据库操作技巧分享(操作mysql)
- MySQL如何查看数据库表结构(mysql查看数据库的表)
- MySQL中使用SET字段类型的方法及注意事项(mysql中使用set)
- MySQL中如何按照指定顺序对数据进行排序(mysql中i排序先后)
- 图C语言与MySQL数据库的连接类图分析(c 与mysql连接的类)
- CS 链接MySQL 实现你的数据库梦想(c s链接mysql)
- 2008年重新启动MySQL数据库之路(2008重启mysql)
- MySQL如何实现上下级分层展示(mysql上下级分层展示)