姬長信(Redy)

如何在MySQL中搜索JSON数据?


我使用json_encoded将数据插入数据库.现在我想搜索“功能”,但我不能.

MySQL查询:

SELECT  `id` ,  `attribs_json` 
FROM  `products` 
WHERE  `attribs_json` REGEXP  '"1":{"value":[^"3"$]'

这个查询显示了所有带有键“1”的行,而值是任何不值为“3”的东西

我的数据是:

{"feature":{"1":{"value":"["2","3"]"},
            "2":{"value":["1"]},
            "5":{"value":""},
            "3":{"value":["1"]},
            "9":{"value":""},
            "4":{"value":"/u0633/u0627/u062a/u0646"},
            "6":{"value":""},
            "7":{"value":""},
            "8":{"value":""}
           },
"show_counter":"0",
"show_counter_discount":""
}}