当前位置:网站首页>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是有限的,甚至在一些情况下没有权限访问该表。
边栏推荐
- Cocos Creator 2. X automatic packaging (build + compile)
- LeetCode1491. Average value of wages after removing the minimum wage and the maximum wage
- [combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
- Detailed explanation of four modes of distributed transaction (Seata)
- Cocos Creator 2.x 自动打包(构建 + 编译)
- Three dimensional reconstruction of deep learning
- Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
- June to - -------
- Multithread 02 thread join
- Pychart error updating package list: connect timed out
猜你喜欢

Low level version of drawing interface (explain each step in detail)

The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)

Remote file contains actual operation

TCP拥塞控制详解 | 3. 设计空间

Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword

Deep understanding of grouping sets statements in SQL

工资3000,靠“视频剪辑”月入40000:会赚钱的人,从不靠拼命!
![[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

How to use AAB to APK and APK to AAB of Google play apps on the shelves

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
随机推荐
嵌入式开发:避免开源软件的7个理由
From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing
Low level version of drawing interface (explain each step in detail)
疫情常态化大背景下,关于远程办公的思考|社区征文
pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
初试scikit-learn库
June to - -------
Pyinstaller is not an internal or external command, nor is it a runnable program or batch file
Record a jar package conflict resolution process
Persisting in output requires continuous learning
记一次jar包冲突解决过程
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
MongoDB 的安装和基本操作
Deep understanding of grouping sets statements in SQL
《天天数学》连载56:二月二十五日
六月 致 -.-- -..- -
特征多项式与常系数齐次线性递推
Advanced Mathematics (Seventh Edition) Tongji University exercises 2-1 personal solutions
QT串口ui设计和解决显示中文乱码
Go language self-study series | if else if statement in golang