当前位置:网站首页>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是有限的,甚至在一些情况下没有权限访问该表。
边栏推荐
- “用Android复刻Apple产品UI”(3)—优雅的数据统计图表
- Three dimensional reconstruction of deep learning
- Multithread 02 thread join
- June to - -------
- First knowledge of database
- Unity项目优化案例一
- Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
- Pyinstaller is not an internal or external command, nor is it a runnable program or batch file
- Hibernate的缓存机制/会话级缓存机制
- Initial test of scikit learn Library
猜你喜欢

深度学习之三维重建

Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day

The mixlab editing team is recruiting teammates~~

2022年Q2加密市场投融资报告:GameFi成为投资关键词

【声明】关于检索SogK1997而找到诸多网页爬虫结果这件事

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)

Cocos Creator 2.x 自动打包(构建 + 编译)

Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14

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

初试scikit-learn库
随机推荐
MongoDB 的安装和基本操作
Explore Cassandra's decentralized distributed architecture
Is it safe to open an account with tongdaxin?
The difference between calling by value and simulating calling by reference
Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!
SVN使用规范
Pychart error updating package list: connect timed out
Record a jar package conflict resolution process
First!! Is lancet hungry? Official documents
Three dimensional reconstruction of deep learning
【LeetCode】94. Middle order traversal of binary tree
Detailed explanation of four modes of distributed transaction (Seata)
Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
2022年Q2加密市场投融资报告:GameFi成为投资关键词
相同切入点的抽取
One article takes you to understand machine learning
App mobile terminal test [4] APK operation
uploads-labs靶场(附源码分析)(更新中)
Function introduction of JMeter thread group
首发!!lancet饿了么官方文档