【发布时间】:2017-07-29 01:08:52
【问题描述】:
如何将存储在字段中的值提取为 json。 customerId 当前存储在 juniferResponse 字段中,例如 {"customerId":1}
以下在我使用的mysql版本中不起作用:
SELECT json_extract(juniferResponse, '$.customerId') AS cid FROM enrolment WHERE juniferResponse IS_NOT_NULL;
我需要从字段不为空或空的 juniferResponse 中提取值。
【问题讨论】:
-
是
juniferResponse作为 json 字符串? -
我想我没有得到你的要求,因为我看这段代码你会做类似
SELECT 1 AS cid FROM enrolment WHERE juniferResponse IS_NOT_NULL;这对我来说没有意义的事情...... -
如果你不需要执行聚合,或者结果的条件,你可以在 PHP 中提取 json json_decode($row['juniferResponse'], true) // 将提取作为数组
-
juniferResponse 是列的名称,它有一个像 {"customerId":1} 这样的存储值我需要获取 1,它是列不为空的 id。
-
@DanIonescu 我宁愿在查询中这样做,因为我必须更新一个大型数据库。