{"id":200184,"date":"2025-05-06T10:21:28","date_gmt":"2025-05-06T02:21:28","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200184\/"},"modified":"2025-05-06T10:21:28","modified_gmt":"2025-05-06T02:21:28","slug":"essential-mysql-operators-and-their-applications","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200184\/","title":{"rendered":"Essential MySQL Operators and Their Applications"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Essential MySQL Operators and Their Applications<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300aEssential MySQL Operators and Their Applications\u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730025581671e186db7e4d.jpg\" class=\"aligncenter\"><\/p>\n<p>mysql \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>\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\u6570\u636e\u8bbf\u95ee\uff1a<\/p>\n<pre>select json_data-&gt;&gt;'$.address' \nfrom customers;\n<\/pre>\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>\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>\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>\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>\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\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u4e3b\u673a\u5b9d\u8d1d\uff01\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u3002<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664 <\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Essential MySQL &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200184","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200184"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200184\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}