【问题标题】:How to parse json column in MySQL Version < 5.7如何在 MySQL 版本 < 5.7 中解析 json 列
【发布时间】:2017-01-11 16:51:27
【问题描述】:

我有一个名为inventory 的专栏。

id ..... inventory

本栏目内容为:

{"STC1":{"count":"1"},"STC2":{"count":0}}

count 值是可变的。 我不想使用应用程序端,我想使用 sql。

例如

我想要什么:

... where STC1.count > 0

... where STC1.count > 1 or STC2.count < 5

【问题讨论】:

    标签: mysql sql json


    【解决方案1】:

    你不能,根据the official MySQL website,5.7.8 版本已经引入了 JSON 支持,它不适用于旧版本。

    对于 MySQL

    您充其量只能检查WHERE inventory LIKE '%"STC1":{"count":"0"%' 以在0 或类似的东西上检测STC1 的行,但仅此而已,而且做任何复杂的事情都会很快变得非常麻烦。

    通常最好存储原子数据以避免此类问题。

    【讨论】:

      猜你喜欢
      • 2021-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-02
      • 1970-01-01
      • 2019-12-31
      • 2014-09-10
      相关资源
      最近更新 更多