我有一个看起来像这样的表格:
uuid investors
1 [{"type": "Organization", "uuid": "435847ec34f541c3b66615de1f346534"}, {"type": "Organization", "uuid": "8bad8a2d97ba4d3c716686244058858e"}]
2 [{"type": "Person", "uuid": "9603633439264ebfb3e46e6052055893"}, {"type": "Organization", "uuid": "a3734663f2d34893afeeda74da26683a"}]
我想根据investors
列列表中的uuid
查询它是否是Organization
和Person
> 因为我稍后必须在这些表中查找那些 uuid
。
编辑
感谢@tcadidot0的回答,我现在可以获得包含type
值和uuid
值的两列。这是结果的屏幕截图。现在,根据 type
,我想访问相应的表并获取具有该特定 uuid
的整行。以下是表格、组织
和 人员
的外观:
组织表
uuid name
435847ec34f541c3b66615de1f346534 XYZ
人员表
uuid name
9603633439264ebfb3e46e6052055893 Bob
最佳答案
我看到您的数据是JSON
。尝试这个查询:
SELECT JSON_EXTRACT(investors, '$**.uuid') AS `uuid`,
JSON_EXTRACT(investors, '$**.type') AS `Type`
FROM mytable;
就像这个 fiddle :https://www.db-fiddle.com/f/8roowVBt5VY6AebWHav9hb/1
我从这里得到了部分答案:https://stackoverflow.com/a/45671728/10910692
关于mysql - 如何在SQL中查询字典类型列值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60560254/