我的数据很脏,现在我正在尝试纠正它们。
数据是这样的:
mysql> select attrs from goods limit 10;
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| attrs |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {"logo": "1", "cover": "", "level": 0, "tag_6": 8, "summary": "L1", "showStatus": 0, "classAmount": 0, "productType": 0, "courseEndTime": 1532572800000, "courseStartTime": 1531706400000} |
| {"logo": "1", "cover": "", "level": 0, "tag_6": 8, "summary": "L1", "showStatus": 0, "classAmount": 0, "productType": 0, "courseEndTime": 1533717600000, "courseStartTime": 1532851200000} |
| {"logo": "1", "cover": "", "level": 0, "tag_6": 8, "summary": "L1", "showStatus": 0, "classAmount": 0, "productType": 0, "courseEndTime": 1534851600000, "courseStartTime": 1533985200000} |
| {"logo": "1", "cover": "", "level": 0, "tag_6": 8, "summary": "L2", "showStatus": 0, "classAmount": 0, "productType": 0, "courseEndTime": 1532594400000, "courseStartTime": 1531728000000} |
| {"logo": "1", "cover": "", "level": 0, "tag_147": 8, "tag_145": 2 "summary": "L2", "showStatus": 0, "classAmount": 0, "productType": 0, "courseEndTime": 1533728400000, "courseStartTime": 1532862000000} |
| {"logo": "1", "cover": "", "level": 0, "tag_6": 8, "summary": "L2", "showStatus": 0, "classAmount": 0, "productType": 0, "courseEndTime": 1534819200000, "courseStartTime": 1533952800000} |
| {"logo": "1", "cover": "", "level": 0, "tag_127": 8, "summary": "NGL", "showStatus": 0, "classAmount": 0, "productType": 0, "courseEndTime": 1532605200000, "courseStartTime": 1531738800000} |
| {"logo": "1", "cover": "", "level": 0, "tag_6": 8, "summary": "NGL", "showStatus": 0, "classAmount": 0, "productType": 0, "courseEndTime": 1533696000000, "courseStartTime": 1532829600000} |
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
如果存在任何这些对,我想删除(key, value)
列中的一些对。attrs
例如tag_147
,并且tag_124
是脏的,那么任何命中对都会被删除。
{"tag_147": 1, "tag_124": 2} ===> {}
{"tag_147": 1 "tag_100":2} ==> {"tag_100": 2}
我怎样才能实现它?谢谢。
我尝试过的是 1. findattrs
包含键tag_147
和tag_124
. 2. 然后更新 attrs。我原来的 Sql 是这样的:
update goods
set json_remove(*XXX*)
where (select json_keys(attrs) from goods ) contains (*tag_147*, *tag_127*)
在这里,我被构造contains
语句阻止了......