拼接/切割筛选列出MySQL表中2个字段值的数字ID部分
2017-02-21 00:00
447 查看
现有一张数据表,数据如下图:
需求是将上图中数据整理成下图格式:
可以用下面的SQL实现:
select distinct substring_index(substring_index(a.roleids,'|',b.help_topic_id+1),'|',-1) 'roleid'
from
(select (CASE when roles = "" then received when received = "" then roles else concat(roles,"|",received) END) 'roleids' from Database_Name.Table_Name) a
join
mysql.help_topic b
on
b.help_topic_id < (length(a.roleids) - length(replace(a.roleids,'|',''))+1) order by roleid;
需求是将上图中数据整理成下图格式:
可以用下面的SQL实现:
select distinct substring_index(substring_index(a.roleids,'|',b.help_topic_id+1),'|',-1) 'roleid'
from
(select (CASE when roles = "" then received when received = "" then roles else concat(roles,"|",received) END) 'roleids' from Database_Name.Table_Name) a
join
mysql.help_topic b
on
b.help_topic_id < (length(a.roleids) - length(replace(a.roleids,'|',''))+1) order by roleid;
相关文章推荐
- mysql 同一张表拼接2个字段
- java拼接字符,数据库字符和数字拼接的字符串作为字段,如ID,主键
- mysql替换字段里数据内容部分字符串
- 关于sql字符串字段的模糊查询与字符串字段里筛选部分值的记录的解决办法
- mysql字段中ID值自动增长
- php列出mysql数据表及字段
- mysql拼接两字段查询
- 根據細表中的主表ID,不重復地列出主表中的字段
- mysql_列出表中所有字段用逗号做分隔符
- mysql 字符串操作,mysql 连接字符串,mysql 拼接字符串,mysql 拼接字段
- mysql 替换字段部分内容
- Mysql更新字段中部分数据的方法
- Mysql的XML字段部分结点更新问题
- Mybatis解决空字符串保存入Mysql数字字段的类型转换问题
- 黄聪:PHP+MySql获取自动增长字段的新添加记录ID值
- mysql select 拼接字段结果CONCAT和CONCAT_WS
- 【mysql--求解求2个或以上字段为NULL 的记录】
- mysql筛选GROUP BY多个字段组合时的用法分享
- mysql中列出所有表格的对应字段
- 替换mysql字段中的匹配的部分关键字