当前位置:网站首页>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是有限的,甚至在一些情况下没有权限访问该表。
边栏推荐
- QT串口ui设计和解决显示中文乱码
- One article takes you to understand machine learning
- [redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)
- Client does not support authentication protocol requested by server; consider upgrading MySQL client
- Is it safe to open an account with flush?
- 疫情常态化大背景下,关于远程办公的思考|社区征文
- 初试scikit-learn库
- Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!
- 程序猿如何快速成长
- Record a jar package conflict resolution process
猜你喜欢

Mixlab编辑团队招募队友啦~~
![[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display](/img/46/c7f566f8fd46d383b055582d680bb7.png)
[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display

Stm32f103c8t6 firmware library lighting

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

Colab works with Google cloud disk

NSQ源码安装运行过程

Interviewer: how does the JVM allocate and recycle off heap memory

Explore Netease's large-scale automated testing solutions see here see here

Remote file contains actual operation

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
随机推荐
Redis high availability and persistence
如何在本机搭建SVN服务器
Hibernate的缓存机制/会话级缓存机制
高等数学(第七版)同济大学 习题2-1 个人解答
Cocos Creator 2.x 自动打包(构建 + 编译)
App mobile terminal test [4] APK operation
Pointcut expression
Effect of ARP package on FTP dump under vxworks-6.6 system
特征多项式与常系数齐次线性递推
[200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
Caching mechanism of Hibernate / session level caching mechanism
Initial test of scikit learn Library
Détails du contrôle de la congestion TCP | 3. Espace de conception
Page dynamics [2]keyframes
First!! Is lancet hungry? Official documents
Jmeter线程组功能介绍
Redis installation under windows and Linux systems
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
8 tips for effective performance evaluation