mysql将某个字段值固定分隔符的内容拆分为多行

该sql的应用场景一般在OA系统中会出现,比如一个人可能在多个部门,在mysql里面会用一个字段来存该用户的部门关系并用“,”分隔开,如果我们想要查看用户所在部门有哪些且每个部门单行显示就需要用借助 mysql.help_topic表了。

SELECT a.id,
substring_index( substring_index( a.dep, ',', b.help_topic_id + 1 ), ',',- 1 ) name,a.time
FROM ding_dep a
JOIN mysql.help_topic b ON b.help_topic_id < ( length( a.dep ) - length( REPLACE ( a.dep, ',', '' ) ) + 1 )
ORDER BY a.id

参考来源:

https://www.jb51.net/article/206106.htm

https://www.cnblogs.com/qxh-beijing2016/p/15076182.html

基于互联网精神,在注明出处的前提下本站文章可自由转载!

本文链接:https://ranjuan.cn/mysql-help-topic/

赞赏

微信赞赏支付宝赞赏

python-monitor-thread-action
php直接输出文件至txt下载(处理中文文件名)
wordpress-weixin-miniprogram-gpl