当前位置:网站首页>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是有限的,甚至在一些情况下没有权限访问该表。
边栏推荐
- Initial test of scikit learn Library
- Golang 装饰器模式以及在NSQ中的使用
- Explore Netease's large-scale automated testing solutions see here see here
- Eleven requirements for test management post
- 用同花顺炒股开户安全吗?
- Low level version of drawing interface (explain each step in detail)
- [200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
- [combinatorics] combinatorial identities (sum of variable terms 3 combinatorial identities | sum of variable terms 4 combinatorial identities | binomial theorem + derivation to prove combinatorial ide
- Pointcut expression
- 在ntpdate同步时间的时候出现“the NTP socket is in use, exiting”
猜你喜欢
One article takes you to understand machine learning
【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
TCP congestion control details | 3 design space
uploads-labs靶场(附源码分析)(更新中)
Jmeter线程组功能介绍
Please be prepared to lose your job at any time within 3 years?
Embedded development: seven reasons to avoid open source software
随机推荐
Expression of request header in different countries and languages
June to - -------
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
《天天数学》连载56:二月二十五日
Redis installation under windows and Linux systems
TCP拥塞控制详解 | 3. 设计空间
程序猿如何快速成长
Break through 1million, sword finger 2million!
[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
Explore Netease's large-scale automated testing solutions see here see here
六月 致 -.-- -..- -
Extraction of the same pointcut
14 topics for performance interviews between superiors and subordinates (4)
Persisting in output requires continuous learning
Unity项目优化案例一
"Remake Apple product UI with Android" (3) - elegant statistical chart
MongoDB 的安装和基本操作
疫情常态化大背景下,关于远程办公的思考|社区征文
【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示