mysql - MySQL Query select concat on json field ids
问题描述
我有这两张桌子
表 1:“身份”
ID | identifier | report_ids
------------------------------
1 | TOP | ["1","2"]
“report_ids”是一个 VARCHAR 列,而不是 JSON
表 2:“报告”
ID | name
------------------------------
1 | Report Food
2 | Report Beverage
我必须从表 Identity 中选择并加入表 Reports 以通过他的 id 获取名称
总之,我希望通过查询得到这个结果:
Result:
ID | identifier | report_names
--------------------------------
1 | TOP | Report Food, Report Beverage
我怎么能用 Query 做到这一点?
在此先感谢:)
解决方案
寻找
SELECT i.id, i.identifier, GROUP_CONCAT(r.name)
FROM Identity i
JOIN Reports r ON LOCATE(CONCAT('"', r.id, '"'), i.report_ids)
GROUP BY i.id, i.identifier
-- WHERE JSON_VALID(i.report_ids)
推荐阅读
- r - 如何将日期与 R 中的许多大文件列表结合起来
- c# - 使用 setter getter 填充/检索列表中的对象列表<>
- javascript - 422 无法处理的实体,当尝试将用户注册详细信息发送到 rails api 时
- html - 我的 display none to flex 过渡不会褪色,即使它是一个单独的淡入淡出动画
- r - 使用 Ordiplot3d 创建 3 维 NMDS 图但难以拥有行标签?
- angular - NgFor 不在 mat-select html 语句中列出我的项目
- python - pyspark 使用 RegexTokenizer 和 Word2Vec 对句子进行标记和向量化
- node.js - Node项目启动应用失败,无法解决错误
- c# - 什么是托管栈和托管堆?
- python - 我在python中结合了pysimplegui和turtle