【发布时间】:2022-11-30 00:01:30
【问题描述】:
从一个包含 json 字典数组的列的表中,我需要每行提取一个键“user_id”的所有值。如果为 null 或空数组,则返回 NULL。类似于 python pandas explode 方法。
数组长度未知。
原表:
【问题讨论】:
标签: mysql arrays json dictionary explode
从一个包含 json 字典数组的列的表中,我需要每行提取一个键“user_id”的所有值。如果为 null 或空数组,则返回 NULL。类似于 python pandas explode 方法。
数组长度未知。
原表:
【问题讨论】:
标签: mysql arrays json dictionary explode
select id, j.user_id from mytable left outer join
json_table(users, '$[*]' columns (user_id int path '$.user_id')) as j on true;
+------+---------+
| id | user_id |
+------+---------+
| 1 | 33 |
| 1 | 34 |
| 2 | 2975 |
| 3 | NULL |
+------+---------+
阅读https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html 了解有关 JSON_TABLE() 函数的更多信息。
【讨论】: