MySQL 数字辅助表去重、排序、行转列
来源:互联网 发布:阿里云服务器ecs配置 编辑:程序博客网 时间:2024/04/29 09:31
一、需求
一个字段有多行记录,查询结果为去重排序的一行记录,例如记录值为:
1,2,4
1,4,5
2,3
23,56,67
3,4
要求查询结果为:
1,2,3,4,5,23,56,67
二、方案
使用数字辅助表实现
一个字段有多行记录,查询结果为去重排序的一行记录,例如记录值为:
1,2,4
1,4,5
2,3
23,56,67
3,4
要求查询结果为:
1,2,3,4,5,23,56,67
二、方案
使用数字辅助表实现
-- 建立数字辅助表 create table nums ( a int not null primary key ); delimiter $$ create procedure pFastCreateNums(cnt int) begin declare s int default 1; truncate table nums; insert into nums select s; while s<=cnt do insert into nums select a+s from nums where a+s <= cnt; set s=s*2; end while; commit; end $$ delimiter ; call pFastCreateNums(1000000); -- 建立测试表 create table t1 ( a varchar(100) ); insert into t1 values('1,2,4'),('1,4,5'),('2,3'),('23,56,67'),('3,4'); commit; -- 查询 select group_concat(a) from (select a from (select cast(substring_index(substring_index(t1.a, ',', nums.a), ',', - 1) as unsigned) a from t1, nums where nums.a <= length(t1.a) - length(replace(t1.a, ',', '')) + 1) t group by a) t1;
0 0
- MySQL 数字辅助表去重、排序、行转列
- MySql快速创建数字辅助表
- MySQL中数字辅助表的建立
- mysql 中文排序 数字排序
- MySQL 用数字辅助表实现复杂的列变行
- MySQL 用数字辅助表实现复杂的列变行
- Mysql数字字符串按照数字排序
- mysql字母数字混合排序
- 构建数字辅助表
- 数字辅助表
- mysql 对varchar型数字排序
- Mysql按数字大小排序String字段
- mysql 按字符串中的数字排序
- MySQL字符串中数字排序的问题
- mysql 对varchar型数字排序
- Mysql的varchar排序按照数字顺序
- MySQL字符串中数字排序的问题
- MySQL字符串中数字排序的问题
- CS231n课程笔记5.2:数据预处理&权重矩阵初始化
- 完成端口(I/O completion)原理
- java,序列化与对象克隆
- python高级编程-生成器
- linux 修改mysql 报错: Last packet sent to the server was 0 ms ago
- MySQL 数字辅助表去重、排序、行转列
- Android在WebView加载数据时展示loading的Dialog
- Android 实现自动备份数据库
- 有源蜂鸣器和无源蜂鸣器讲解
- Mesh网格篇(二)网格的快速切割
- iOS UIWebView 图片自适应屏幕宽度
- angular2 +Polymer 环境搭建
- 伪聊天室实现记录
- ForForDemo