当前位置:网站首页>Mysql 将逗号隔开的属性字段数据由列转行
Mysql 将逗号隔开的属性字段数据由列转行
2022-07-03 16:19:00 【小陈-程序员】
Mysql 将逗号隔开的属性字段转行为行数据
Mysql 将逗号隔开的属性字段转行为行数据。
- 场景:
在开发时,我们会根据需求进行数据库表的设计。有时我们在设计数据表时无法很好的符合三大范式,原因场景的复杂性,假如时时刻刻遵顼三大范式,会增加我们的开发量。有时候我们会在一个属性值里用逗号隔开去存储一些id值等。当在查询的时候就需要将属性转换为行。
- 数据 :

- 解决:
select a.*,SUBSTRING_INDEX(SUBSTRING_INDEX(a.content,',',b.id),',',-1) content
from temp a
join temp b
where b.id <= LENGTH(a.content)-LENGTH(REPLACE(a.content,',',''))+1
- 结果:

- 函数解析
SUBSTRING_INDEX : 获取分隔符隔开后,根据最后参数索引获取字符串 ,负数为倒数
LENGTH : 字符串 长度
REPLACE : 替换字符串
总结:
join 表需要寻找一个表属性为1开始递增的。通常会利用 mysql.help_topic 这张表,但是这张表的数据id是有限的,甚至在一些情况下没有权限访问该表。
边栏推荐
- Unity project optimization case 1
- The difference between calling by value and simulating calling by reference
- Go language self-study series | if else if statement in golang
- 利用MySQL中的乐观锁和悲观锁实现分布式锁
- Thinking about telecommuting under the background of normalization of epidemic | community essay solicitation
- Record windows10 installation tensorflow-gpu2.4.0
- Unreal_DataTable 实现Id自增与设置RowName
- Why does the std:: string operation perform poorly- Why do std::string operations perform poorly?
- Develop team OKR in the way of "crowdfunding"
- 切入点表达式
猜你喜欢

初试scikit-learn库

记一次jar包冲突解决过程

Myopia: take off or match glasses? These problems must be understood clearly first

NSQ源码安装运行过程

ThreeJS 第二篇:顶点概念、几何体结构

Remote file contains actual operation

Initial test of scikit learn Library

Record a jar package conflict resolution process

TCP congestion control details | 3 design space

跟我学企业级flutter项目:简化框架demo参考
随机推荐
First!! Is lancet hungry? Official documents
ThreeJS 第二篇:顶点概念、几何体结构
TCP拥塞控制详解 | 3. 设计空间
远程文件包含实操
[combinatorics] combinatorial identity (sum of variable upper terms 1 combinatorial identity | summary of three combinatorial identity proof methods | proof of sum of variable upper terms 1 combinator
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (II)
1287. Elements that appear more than 25% in an ordered array
Cocos Creator 2. X automatic packaging (build + compile)
首发!!lancet饿了么官方文档
【声明】关于检索SogK1997而找到诸多网页爬虫结果这件事
[combinatorics] combinatorial identities (review of eight combinatorial identities | product of combinatorial identities 1 | proof | use scenario | general method for finding combinatorial numbers)
“用Android复刻Apple产品UI”(3)—优雅的数据统计图表
如何在本机搭建SVN服务器
Reflection on some things
Mongodb installation and basic operation
Record a jar package conflict resolution process
Interviewer: how does the JVM allocate and recycle off heap memory
[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display
Principles of several common IO models
Client does not support authentication protocol requested by server; consider upgrading MySQL client