【发布时间】:2019-02-02 05:10:23
【问题描述】:
MySQL 5.7 版
鉴于 h.ent_rollup 长度始终 >=4,并且我想在仅包含单个数组的 JSON 数据字段中获取倒数第二个数组元素:
ent_rollup 的 JSON 值示例:
["15","26","57","28","89","10","11","12"]
例子:我想要这个
SELECT h.`ent_rollup`->>CONCAT('"$[',(JSON_LENGTH(h.`ent_rollup`))-2,']"') FROM hierarchy h
翻译成这个
SELECT h.`ent_rollup`->>"$[6]" FROM hierarchy h
我想找回11,但我收到了这个错误:
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'concat('"$[',
(json_length(h.`ent_rollup`))-2,']"') from hierarchy h
where h.`en' at line 1
【问题讨论】: