从mysql表中搜索json值

时间:2014-08-09 07:36:45

标签: mysql json

我有一些数据:

id  name  ccode  json
1   john   231   {"age": 12,"score": 90}
2   danny   231   {"age": 22,"score": 87}
3   danniel   231   {"age": 18,"score": 48}
4   sara   431   {"age": 16,"score": 67}

现在,我想让他们年龄的所有用户的所有字段都在15到24之间,而且他们的ccode是231。

结果必须是:

2   danny   231   {"age": 22,"score": 87}
3   danniel   231   {"age": 18,"score": 48}

1 个答案:

答案 0 :(得分:1)

您可以使用以下查询

select id,name,ccode,json, CAST(SUBSTRING(SUBSTRING_INDEX(json, ',', 1)  FROM 8)  AS UNSIGNED) as val 
from events 
where ccode=231  having val>15 and val<24;