{"id":7770,"date":"2024-11-14T10:51:23","date_gmt":"2024-11-14T02:51:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7770\/"},"modified":"2024-11-14T10:51:23","modified_gmt":"2024-11-14T02:51:23","slug":"%e5%a6%82%e4%bd%95%e7%bb%9f%e8%ae%a1-mysql-5-7-%e4%b8%ad-json-%e6%95%b0%e7%bb%84%e7%89%b9%e5%ae%9a%e5%85%83%e7%b4%a0%e5%87%ba%e7%8e%b0%e7%9a%84%e6%ac%a1%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7770\/","title":{"rendered":"\u5982\u4f55\u7edf\u8ba1 MySQL 5.7 \u4e2d JSON \u6570\u7ec4\u7279\u5b9a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173122708244451.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u7edf\u8ba1 MySQL 5.7 \u4e2d JSON \u6570\u7ec4\u7279\u5b9a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7edf\u8ba1 MySQL 5.7 \u4e2d JSON \u6570\u7ec4\u7279\u5b9a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7edf\u8ba1  \u4e2d json \u6570\u7ec4\u4e2d\u7279\u5b9a\u503c\u7684\u9891\u6b21<\/strong><\/p>\n<p>\u4f60\u5e0c\u671b\u7edf\u8ba1 json \u6570\u7ec4\u4e2d\u7279\u5b9a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\u3002\u5728\u4e0b\u6587\u7ed9\u51fa\u7684\u89e3\u51b3\u65b9\u6848\u4e2d\uff0c\u6211\u4eec\u8df3\u8fc7\u4e86\u4f7f\u7528 json_table\uff0c\u56e0\u4e3a\u4f60\u7684 mysql \u7248\u672c\u4e3a 5.7\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u63d0\u51fa\u4e86\u4ee5\u4e0b\u65b9\u6848\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 json_search \u67e5\u627e\u5305\u542b\u7279\u5b9a\u5143\u7d20\u7684\u8bb0\u5f55\u3002<\/li>\n<li>\u5728\u4ee3\u7801\u4e2d\u5bf9\u67e5\u8be2\u7ed3\u679c\u8fdb\u884c\u5904\u7406\u4ee5\u8ba1\u7b97\u6bcf\u4e2a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u6539\u8fdb\u7684\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u7ecf\u6539\u8fdb\u7684\u65b9\u6848\u53ef\u4ee5\u7edf\u8ba1\u6bcf\u4e2a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\uff1a<\/p>\n<pre>SELECT\n    count( JSON_SEARCH( tags, 'one', \"3467562849402896\" ) ),\n    count( JSON_SEARCH( tags, 'one', \"3467562861985809\" ) ),\n    count( JSON_SEARCH( tags, 'one', \"3465044211793921\" ) )\nFROM\n    XXXXXXXXXX<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n<ul>\n<li>json_search \u51fd\u6570\u7528\u4e8e\u5728\u7ed9\u5b9a\u7684 json \u6570\u636e\u4e2d\u641c\u7d22\u6307\u5b9a\u7684\u5143\u7d20\u3002<\/li>\n<li>count() \u7528\u4e8e\u8ba1\u7b97\u6bcf\u4e2a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\u3002<\/li>\n<li>&#8216;one&#8217; \u8868\u793a json \u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u952e\u540d\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u7edf\u8ba1 MySQL 5.7 \u4e2d JSON \u6570\u7ec4\u7279\u5b9a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u7edf\u8ba1 \u4e2d json \u6570\u7ec4\u4e2d\u7279\u5b9a\u503c\u7684\u9891\u6b21 \u4f60\u5e0c\u671b\u7edf\u8ba1 json \u6570\u7ec4\u4e2d\u7279\u5b9a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\u3002\u5728\u4e0b\u6587\u7ed9\u51fa\u7684\u89e3\u51b3\u65b9\u6848\u4e2d\uff0c\u6211\u4eec\u8df3\u8fc7\u4e86\u4f7f\u7528 json_table\uff0c\u56e0\u4e3a\u4f60\u7684 mysql \u7248\u672c\u4e3a 5.7\u3002 \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u63d0\u51fa\u4e86\u4ee5\u4e0b\u65b9\u6848\uff1a \u4f7f\u7528 json_search \u67e5\u627e\u5305\u542b\u7279\u5b9a\u5143\u7d20\u7684\u8bb0\u5f55\u3002 \u5728\u4ee3\u7801\u4e2d\u5bf9\u67e5\u8be2\u7ed3\u679c\u8fdb\u884c\u5904\u7406\u4ee5\u8ba1\u7b97\u6bcf\u4e2a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\u3002 \u6539\u8fdb\u7684\u65b9\u6848\uff1a \u4ee5\u4e0b\u7ecf\u6539\u8fdb\u7684\u65b9\u6848\u53ef\u4ee5\u7edf\u8ba1\u6bcf\u4e2a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\uff1a SELECT count( JSON_SEARCH( tags, &#8216;one&#8217;, &#8220;3467562849402896&#8221; ) ), count( JSON_SEARCH( tags, &#8216;one&#8217;, &#8220;3467562861985809&#8221; ) ), count( JSON_SEARCH( tags, &#8216;one&#8217;, &#8220;3465044211793921&#8221; ) ) FROM XXXXXXXXXX \u767b\u5f55\u540e\u590d\u5236 \u89e3\u91ca\uff1a json_search \u51fd\u6570\u7528\u4e8e\u5728\u7ed9\u5b9a\u7684 json \u6570\u636e\u4e2d\u641c\u7d22\u6307\u5b9a\u7684\u5143\u7d20\u3002 count() \u7528\u4e8e\u8ba1\u7b97\u6bcf\u4e2a\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\u3002 &#8216;one&#8217; \u8868\u793a json \u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u952e\u540d\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u7edf\u8ba1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7770","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7770"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7770\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}