简体   繁体   English

MySQL-在JSON密钥对值中选择数据

[英]MySQL - SELECT data where JSON key-pair value is something

I'm trying to construct a MySQL query that would do the following: 我正在尝试构建将执行以下操作的MySQL查询:

Sample Data: 样本数据:

---------------------------------------------
|                  colm                     |
---------------------------------------------
|{"level":10, "something": "blah", etc}     |
---------------------------------------------
|{"level":3, "something": "blah", etc}     |
---------------------------------------------
|{"level":7, "something": "blah", etc}     |
---------------------------------------------
|{"level":21, "something": "blah", etc}     |

I need to SELECT rows where colm LIKE "%?%" with the ? 我需要SELECT行,其中colm LIKE "%?%" ? being level is less than or equal to ( <= ) some value. 级别小于或等于( <= )一些值。 For example, SELECT ing all rows where colm has the JSON string's level key-pair value <= 8 , getting the middle two rows. 例如,对colm具有JSON字符串level密钥对值<= 8所有行进行SELECT colm ,得到中间两行。

How can I do this? 我怎样才能做到这一点? I'm thinking something with JSON functions instead of using LIKE and % wildcards, but I'm not sure exactly what I need to do. 我在考虑使用JSON函数而不是使用LIKE%通配符,但是我不确定我到底需要做什么。

尝试这个:

SELECT * FROM <your-table> WHERE colm->"$.level" <= 8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM