{"id":6722,"date":"2024-11-14T13:41:45","date_gmt":"2024-11-14T05:41:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6722\/"},"modified":"2024-11-14T13:41:45","modified_gmt":"2024-11-14T05:41:45","slug":"essential-mysql-operators-and-their-applications","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6722\/","title":{"rendered":"Essential MySQL Operators and Their Applications"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172982266886424.jpg\" class=\"aligncenter\" title=\"Essential MySQL Operators and Their Applications\u63d2\u56fe\" alt=\"Essential MySQL Operators and Their Applications\u63d2\u56fe\" \/><\/p>\n<p> \u8fd0\u7b97\u7b26\u662f\u5f00\u53d1\u4eba\u5458\u7684\u5173\u952e\u5de5\u5177\uff0c\u53ef\u5b9e\u73b0\u7cbe\u786e\u7684\u6570\u636e\u64cd\u4f5c\u548c\u5206\u6790\u3002\u5b83\u4eec\u6db5\u76d6\u4e86\u4e00\u7cfb\u5217\u529f\u80fd\uff0c\u5305\u62ec\u8d4b\u503c\u3001\u6570\u636e\u6bd4\u8f83\u548c\u590d\u6742\u6a21\u5f0f\u5339\u914d\u3002\u65e0\u8bba\u60a8\u662f\u5904\u7406 json \u6570\u636e\u8fd8\u662f\u6839\u636e\u6761\u4ef6\u8fc7\u6ee4\u8bb0\u5f55\uff0c\u4e86\u89e3\u8fd9\u4e9b\u8fd0\u7b97\u7b26\u5bf9\u4e8e\u9ad8\u6548\u7684\u6570\u636e\u5e93\u7ba1\u7406\u90fd\u81f3\u5173\u91cd\u8981\u3002 <\/p>\n<p>\u672c\u6307\u5357\u4ecb\u7ecd\u4e86\u6700\u91cd\u8981\u7684 mysql \u8fd0\u7b97\u7b26\uff0c\u5e76\u901a\u8fc7\u5b9e\u9645\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u5b83\u4eec\uff0c\u4f7f\u5f00\u53d1\u4eba\u5458\u66f4\u5bb9\u6613\u5c06\u5b83\u4eec\u96c6\u6210\u5230\u6570\u636e\u5e93\u67e5\u8be2\u4e2d\u3002<\/p>\n<h2> mysql \u8fd0\u7b97\u7b26 <\/h2>\n<p><strong>:=<\/strong> \u2014 \u7528\u4e8e\u5c06\u503c\u76f4\u63a5\u5206\u914d\u7ed9\u53d8\u91cf\u4ee5\u4fbf\u5728\u67e5\u8be2\u4e2d\u7acb\u5373\u4f7f\u7528\uff1a<\/p>\n<pre>set @total := 50;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4f1a\u5c06 @total \u8bbe\u7f6e\u4e3a 50\uff0c\u6682\u65f6\u5b58\u50a8\u4ee5\u4f9b\u4f7f\u7528\u3002<\/p>\n<p><strong>&gt;&gt;<\/strong> \u2014 \u4ece json \u5217\u4e2d\u63d0\u53d6\u503c\u5e76\u53d6\u6d88\u5f15\u53f7\uff0c\u7b80\u5316\uff1a<\/p>\n<pre>select json_data-&gt;&gt;'$.address' \nfrom customers;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b83\u4ece json \u5bf9\u8c61\u4e2d\u83b7\u53d6\u5730\u5740\u5b57\u6bb5\u3002<\/p>\n<p><strong>between x \u548c y<\/strong> \u2014 \u9a8c\u8bc1\u503c\u662f\u5426\u5728\u5b9a\u4e49\u7684\u8303\u56f4\u5185\uff1a<\/p>\n<pre>select * \nfrom inventory \nwhere price between 100 and 500;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fc7\u6ee4\u6307\u5b9a\u4ef7\u683c\u8303\u56f4\u5185\u7684\u4ea7\u54c1\u3002<\/p>\n<p><strong>\u662f | is not<\/strong> \u2014 \u68c0\u67e5\u503c\u662f\u5426\u4e3a null \u6216\u5176\u4ed6\u72b6\u6001\uff0c\u5bf9\u4e8e\u9a8c\u8bc1\u5f88\u6709\u7528\uff1a<\/p>\n<pre>select * \nfrom users \nwhere active is not null;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd4\u56de\u72b6\u6001\u4e3a\u975e\u7a7a\u7684\u7528\u6237\u3002<\/p>\n<p><strong>rlike<\/strong> \u2014 \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u5b57\u7b26\u4e32\uff0c\u63d0\u4f9b\u6bd4 like \u66f4\u9ad8\u7ea7\u7684\u6a21\u5f0f\u5339\u914d\u529f\u80fd\uff1a<\/p>\n<pre>select * \nfrom logs \nwhere event rlike 'error.*';\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u68c0\u7d22\u4e8b\u4ef6\u63cf\u8ff0\u5f00\u5934\u5305\u542b\u201c\u9519\u8bef\u201d\u7684\u65e5\u5fd7\u3002<\/p>\n<p><strong>space()<\/strong> \u2014 \u751f\u6210\u586b\u5145\u7a7a\u683c\u7684\u5b57\u7b26\u4e32\u6216\u8f93\u51fa null:<\/p>\n<pre>SELECT SPACE(3);\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ea7\u751f\u4e09\u4e2a\u7a7a\u683c\uff0c\u53ef\u7528\u4e8e\u683c\u5f0f\u5316\u76ee\u7684\u3002<\/p>\n<h2> \u5e38\u95ee\u95ee\u9898 <\/h2>\n<p><strong>\u54ea\u91cc\u53ef\u4ee5\u627e\u5230\u6240\u6709 mysql \u8fd0\u7b97\u7b26\u7684\u5217\u8868\uff1f<\/strong><\/p>\n<p>mysql \u5b98\u65b9\u6587\u6863\u5305\u542b\u5b8c\u6574\u7684\u8fd0\u7b97\u7b26\u5217\u8868\u3002<\/p>\n<p><strong>mysql \u4e2d\u6700\u5e38\u7528\u7684\u8fd0\u7b97\u7b26\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<p>\u6bd4\u8f83\uff08=\u3001!=\uff09\u3001like \u548c is null \u7b49\u8fd0\u7b97\u7b26\u7ecf\u5e38\u7528\u4e8e\u6570\u636e\u8fc7\u6ee4\u3002<\/p>\n<p><strong>mysql \u8fd0\u7b97\u7b26\u4f1a\u5bf9\u6570\u636e\u5e93\u4ea7\u751f\u8d1f\u9762\u5f71\u54cd\u5417\uff1f<\/strong><\/p>\n<p>\u867d\u7136\u5b83\u4eec\u4e0d\u4f1a\u635f\u574f\u6570\u636e\u5e93\uff0c\u4f46\u4f4e\u6548\u4f7f\u7528\u53ef\u80fd\u4f1a\u5f71\u54cd\u67e5\u8be2\u901f\u5ea6\u3002<\/p>\n<p><strong>dbvisualizer \u5982\u4f55\u589e\u5f3a\u6570\u636e\u5e93\u7ba1\u7406\uff1f<\/strong><\/p>\n<p>dbvisualizer \u6709\u52a9\u4e8e\u4f18\u5316\u67e5\u8be2\u3001\u8bca\u65ad\u95ee\u9898\u5e76\u63d0\u9ad8\u6574\u4f53\u6570\u636e\u5e93\u6027\u80fd\u3002<\/p>\n<h2> \u7ed3\u8bba <\/h2>\n<p>\u4e86\u89e3 mysql \u8fd0\u7b97\u7b26\u5bf9\u4e8e\u5bfb\u6c42\u4f18\u5316\u6570\u636e\u5e93\u67e5\u8be2\u548c\u63d0\u9ad8\u6027\u80fd\u7684\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\u81f3\u5173\u91cd\u8981\u3002\u5728\u6b64\u5904\u7684\u5b8c\u6574\u6587\u7ae0\u4e2d\u4e86\u89e3\u6709\u5173\u8fd9\u4e9b\u57fa\u672c\u5de5\u5177\u7684\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fEssential MySQL Operators and Their Applications\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>\u8fd0\u7b97\u7b26\u662f\u5f00\u53d1\u4eba\u5458\u7684\u5173\u952e\u5de5\u5177\uff0c\u53ef\u5b9e\u73b0\u7cbe\u786e\u7684\u6570\u636e\u64cd\u4f5c\u548c\u5206\u6790\u3002\u5b83\u4eec\u6db5\u76d6\u4e86\u4e00\u7cfb\u5217\u529f\u80fd\uff0c\u5305\u62ec\u8d4b\u503c\u3001\u6570\u636e\u6bd4\u8f83\u548c\u590d\u6742\u6a21\u5f0f\u5339\u914d\u3002\u65e0\u8bba\u60a8\u662f\u5904\u7406 json \u6570\u636e\u8fd8\u662f\u6839\u636e\u6761\u4ef6\u8fc7\u6ee4\u8bb0\u5f55\uff0c\u4e86\u89e3\u8fd9\u4e9b\u8fd0\u7b97\u7b26\u5bf9\u4e8e\u9ad8\u6548\u7684\u6570\u636e\u5e93\u7ba1\u7406\u90fd\u81f3\u5173\u91cd\u8981\u3002 \u672c\u6307\u5357\u4ecb\u7ecd\u4e86\u6700\u91cd\u8981\u7684 mysql \u8fd0\u7b97\u7b26\uff0c\u5e76\u901a\u8fc7\u5b9e\u9645\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u5b83\u4eec\uff0c\u4f7f\u5f00\u53d1\u4eba\u5458\u66f4\u5bb9\u6613\u5c06\u5b83\u4eec\u96c6\u6210\u5230\u6570\u636e\u5e93\u67e5\u8be2\u4e2d\u3002 mysql \u8fd0\u7b97\u7b26 := \u2014 \u7528\u4e8e\u5c06\u503c\u76f4\u63a5\u5206\u914d\u7ed9\u53d8\u91cf\u4ee5\u4fbf\u5728\u67e5\u8be2\u4e2d\u7acb\u5373\u4f7f\u7528\uff1a set @total := 50; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u4f1a\u5c06 @total \u8bbe\u7f6e\u4e3a 50\uff0c\u6682\u65f6\u5b58\u50a8\u4ee5\u4f9b\u4f7f\u7528\u3002 &gt;&gt; \u2014 \u4ece json \u5217\u4e2d\u63d0\u53d6\u503c\u5e76\u53d6\u6d88\u5f15\u53f7\uff0c\u7b80\u5316\uff1a select json_data-&gt;&gt;&#8217;$.address&#8217; from customers; \u767b\u5f55\u540e\u590d\u5236 \u5b83\u4ece json \u5bf9\u8c61\u4e2d\u83b7\u53d6\u5730\u5740\u5b57\u6bb5\u3002 between x \u548c y \u2014 \u9a8c\u8bc1\u503c\u662f\u5426\u5728\u5b9a\u4e49\u7684\u8303\u56f4\u5185\uff1a select * from inventory where price between 100 and 500; \u767b\u5f55\u540e\u590d\u5236 \u8fc7\u6ee4\u6307\u5b9a\u4ef7\u683c\u8303\u56f4\u5185\u7684\u4ea7\u54c1\u3002 \u662f | is not [&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-6722","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6722","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=6722"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6722\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}