创建表
CREATE TABLE t_json(id INT PRIMARY KEY, NAME VARCHAR(20) , info JSON);
插入记录
INSERT INTO t_json(id,sname,info) VALUES(1 ,'test','{"time":"2017-01-01 13:00:00","ip":"192.168.1.1","result":"fail"}');
INSERT INTO t_json(id,sname,info) VALUES(2 ,'my',JSON_OBJECT("time",NOW(),'ip','192.168.1.1','result','fail'));
查询IP键
SELECT sname,JSON_EXTRACT(info,'$.ip') FROM t_json;
查询有多少个键
SELECT id,json_keys(info) AS "keys" FROM t_json;
删除键
UPDATE t_json SET info = json_remove(info,'$.ip');
增加键
UPDATE t_json SET info = json_set(info,'$.ip','192.168.1.1');
变更值
UPDATE t_json SET info = json_set(info,'$.ip','192.168.1.2');
UPDATE t_staff SET details = json_set(details,'$.account','13245678');
UPDATE t_staff SET details = json_set(details,'$.ciInfo','13245678');
UPDATE t_salary SET correls = json_set(correls,'$.staff.identity','32068219960429543X');
select identity from t_staff WHERE identity = 'f911a090a6ba11e846f0eff2f620b204';
SELECT * FROM t_help WHERE correls -> '$.staff.identity' not in (select identity from t_staff);
select identity from t_staff;
select count(*) from t_staff;
网友评论