{"id":6354,"date":"2024-07-18T19:57:27","date_gmt":"2024-07-18T11:57:27","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6354"},"modified":"2024-07-18T19:57:27","modified_gmt":"2024-07-18T11:57:27","slug":"%e6%95%b0%e6%8d%ae%e5%ba%93%e4%bb%80%e4%b9%88%e6%83%85%e5%86%b5%e4%b8%8b%e5%ba%94%e8%af%a5%e4%bd%bf%e7%94%a8%e7%b4%a2%e5%bc%95","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6354","title":{"rendered":"\u6570\u636e\u5e93\u4ec0\u4e48\u60c5\u51b5\u4e0b\u5e94\u8be5\u4f7f\u7528\u7d22\u5f15"},"content":{"rendered":"<p>\u4f7f\u7528\u7d22\u5f15\u7684\u9700\u6c42\u5e76\u4e0d\u4e25\u683c\u4f9d\u8d56\u4e8e\u6570\u636e\u91cf\u7684\u5177\u4f53\u5927\u5c0f\uff0c\u800c\u662f\u4f9d\u8d56\u4e8e\u6570\u636e\u8bbf\u95ee\u6a21\u5f0f\u548c\u67e5\u8be2\u6027\u80fd\u9700\u6c42\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u968f\u7740\u6570\u636e\u91cf\u7684\u589e\u52a0\uff0c\u7d22\u5f15\u7684\u4f5c\u7528\u4f1a\u53d8\u5f97\u66f4\u52a0\u660e\u663e\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5373\u4f7f\u6570\u636e\u91cf\u76f8\u5bf9\u8f83\u5c0f\uff0c\u4f7f\u7528\u7d22\u5f15\u4e5f\u80fd\u663e\u8457\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u9700\u8981\u8003\u8651\u7684\u56e0\u7d20\u548c\u6307\u5bfc\u539f\u5219\uff1a<\/p>\n<h3>\u5173\u952e\u56e0\u7d20<\/h3>\n<ol>\n<li>\n<p><strong>\u67e5\u8be2\u6027\u80fd<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u67e5\u8be2\u901f\u5ea6\u53d8\u6162\uff0c\u7279\u522b\u662f\u5728\u626b\u63cf\u5927\u91cf\u6570\u636e\u884c\u65f6\uff0c\u5e94\u8003\u8651\u4f7f\u7528\u7d22\u5f15\u3002<\/li>\n<li>\u5bf9\u4e8e\u9891\u7e41\u7684\u67e5\u8be2\uff0c\u7279\u522b\u662f\u90a3\u4e9b\u6d89\u53ca\u6392\u5e8f\u3001\u5206\u7ec4\u3001\u8fde\u63a5\u6216\u8303\u56f4\u67e5\u8be2\u7684\uff0c\u7d22\u5f15\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u67e5\u8be2\u9891\u7387<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u67d0\u4e9b\u67e5\u8be2\u975e\u5e38\u9891\u7e41\uff0c\u5373\u4f7f\u6570\u636e\u91cf\u4e0d\u5927\uff0c\u7d22\u5f15\u4e5f\u80fd\u63d0\u9ad8\u7cfb\u7edf\u7684\u6574\u4f53\u54cd\u5e94\u901f\u5ea6\u548c\u7528\u6237\u4f53\u9a8c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8868\u5927\u5c0f<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4e00\u822c\u6765\u8bf4\uff0c\u5f53\u8868\u7684\u884c\u6570\u8d85\u8fc7\u6570\u5343\u884c\u65f6\uff0c\u4f7f\u7528\u7d22\u5f15\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u67e5\u8be2\u901f\u5ea6\u3002<\/li>\n<li>\u968f\u7740\u884c\u6570\u589e\u52a0\u5230\u6570\u4e07\u3001\u6570\u5341\u4e07\u751a\u81f3\u66f4\u591a\u65f6\uff0c\u7d22\u5f15\u7684\u4f5c\u7528\u53d8\u5f97\u66f4\u52a0\u91cd\u8981\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u6a21\u578b\u548c\u8bbf\u95ee\u6a21\u5f0f<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u8868\u5177\u6709\u9891\u7e41\u7684\u8bfb\u64cd\u4f5c\uff0c\u800c\u4e0d\u662f\u9891\u7e41\u7684\u5199\u64cd\u4f5c\uff0c\u7d22\u5f15\u7684\u597d\u5904\u66f4\u4e3a\u660e\u663e\u3002<\/li>\n<li>\u5bf9\u4e8e\u5199\u64cd\u4f5c\u8f83\u591a\u7684\u573a\u666f\uff0c\u9700\u8981\u6743\u8861\u7d22\u5f15\u5e26\u6765\u7684\u5199\u5165\u5f00\u9500\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u793a\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5177\u4f53\u7684\u60c5\u5883\uff0c\u8bf4\u660e\u4f55\u65f6\u9700\u8981\u4f7f\u7528\u7d22\u5f15\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u7b80\u5355\u67e5\u8be2<\/strong>\uff1a<\/p>\n<pre><code class=\"language-sql\">SELECT * FROM orders WHERE customer_id = 12345;<\/code><\/pre>\n<ul>\n<li>\u5982\u679c <code>orders<\/code> \u8868\u6709\u6210\u5343\u4e0a\u4e07\u7684\u8bb0\u5f55\uff0c\u6ca1\u6709\u7d22\u5f15\u65f6\u67e5\u8be2\u901f\u5ea6\u4f1a\u5f88\u6162\u3002\u5728 <code>customer_id<\/code> \u4e0a\u521b\u5efa\u7d22\u5f15\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u67e5\u8be2\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6392\u5e8f\u67e5\u8be2<\/strong>\uff1a<\/p>\n<pre><code class=\"language-sql\">SELECT * FROM products ORDER BY price DESC;<\/code><\/pre>\n<ul>\n<li>\u5982\u679c <code>products<\/code> \u8868\u6709\u5f88\u591a\u8bb0\u5f55\uff0c\u5728 <code>price<\/code> \u4e0a\u521b\u5efa\u7d22\u5f15\u53ef\u4ee5\u52a0\u5feb\u6392\u5e8f\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8303\u56f4\u67e5\u8be2<\/strong>\uff1a<\/p>\n<pre><code class=\"language-sql\">SELECT * FROM sales WHERE sale_date BETWEEN '2023-01-01' AND '2023-06-30';<\/code><\/pre>\n<ul>\n<li>\u5982\u679c <code>sales<\/code> \u8868\u7684\u6570\u636e\u91cf\u8f83\u5927\uff0c\u5728 <code>sale_date<\/code> \u4e0a\u521b\u5efa\u7d22\u5f15\u53ef\u4ee5\u663e\u8457\u52a0\u5feb\u8303\u56f4\u67e5\u8be2\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8fde\u63a5\u67e5\u8be2<\/strong>\uff1a<\/p>\n<pre><code class=\"language-sql\">SELECT orders.order_id, customers.name\nFROM orders\nJOIN customers ON orders.customer_id = customers.customer_id\nWHERE customers.region = 'North America';<\/code><\/pre>\n<ul>\n<li>\u5982\u679c <code>orders<\/code> \u548c <code>customers<\/code> \u8868\u90fd\u6709\u5f88\u591a\u8bb0\u5f55\uff0c\u5206\u522b\u5728 <code>orders.customer_id<\/code> \u548c <code>customers.customer_id<\/code> \u4e0a\u521b\u5efa\u7d22\u5f15\uff0c\u53ef\u4ee5\u52a0\u5feb\u8fde\u63a5\u67e5\u8be2\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>\u6307\u5bfc\u539f\u5219<\/h3>\n<ol>\n<li><strong>\u7ecf\u5e38\u67e5\u8be2\u7684\u5217<\/strong>\uff1a\u5728\u7ecf\u5e38\u51fa\u73b0\u5728 WHERE\u3001JOIN\u3001ORDER BY\u3001GROUP BY \u5b50\u53e5\u4e2d\u7684\u5217\u4e0a\u521b\u5efa\u7d22\u5f15\u3002<\/li>\n<li><strong>\u9ad8\u9009\u62e9\u6027\u5217<\/strong>\uff1a\u5728\u9009\u62e9\u6027\u9ad8\u7684\u5217\u4e0a\u521b\u5efa\u7d22\u5f15\uff0c\u5373\u5217\u4e2d\u4e0d\u540c\u503c\u7684\u6570\u91cf\u8f83\u591a\uff0c\u76f8\u5bf9\u5c11\u91cf\u7684\u91cd\u590d\u503c\u3002<\/li>\n<li><strong>\u907f\u514d\u8fc7\u591a\u7d22\u5f15<\/strong>\uff1a\u867d\u7136\u7d22\u5f15\u53ef\u4ee5\u52a0\u5feb\u67e5\u8be2\u901f\u5ea6\uff0c\u4f46\u8fc7\u591a\u7684\u7d22\u5f15\u4f1a\u589e\u52a0\u5199\u64cd\u4f5c\u7684\u5f00\u9500\uff0c\u5e76\u5360\u7528\u66f4\u591a\u7684\u5b58\u50a8\u7a7a\u95f4\u3002\u6839\u636e\u5b9e\u9645\u9700\u6c42\u5408\u7406\u521b\u5efa\u7d22\u5f15\u3002<\/li>\n<li><strong>\u5b9a\u671f\u7ef4\u62a4\u7d22\u5f15<\/strong>\uff1a\u5b9a\u671f\u68c0\u67e5\u548c\u91cd\u5efa\u7d22\u5f15\uff0c\u7279\u522b\u662f\u5728\u5927\u91cf\u6570\u636e\u63d2\u5165\u3001\u66f4\u65b0\u6216\u5220\u9664\u540e\uff0c\u786e\u4fdd\u7d22\u5f15\u6027\u80fd\u6700\u4f73\u3002<\/li>\n<\/ol>\n<h3>\u5b9e\u8df5\u4e2d\u7684\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ol>\n<li><strong>\u76d1\u63a7\u548c\u4f18\u5316<\/strong>\uff1a\u4f7f\u7528 MySQL \u63d0\u4f9b\u7684 EXPLAIN \u547d\u4ee4\u6765\u5206\u6790\u67e5\u8be2\u8ba1\u5212\uff0c\u4e86\u89e3\u7d22\u5f15\u7684\u4f7f\u7528\u60c5\u51b5\uff0c\u627e\u5230\u9700\u8981\u4f18\u5316\u7684\u67e5\u8be2\u3002<\/li>\n<li><strong>\u7d22\u5f15\u7edf\u8ba1\u4fe1\u606f<\/strong>\uff1a\u786e\u4fdd\u6570\u636e\u5e93\u7684\u7d22\u5f15\u7edf\u8ba1\u4fe1\u606f\u662f\u6700\u65b0\u7684\uff0c\u6570\u636e\u5e93\u4f18\u5316\u5668\u4f9d\u8d56\u8fd9\u4e9b\u7edf\u8ba1\u4fe1\u606f\u6765\u9009\u62e9\u6700\u4f73\u7684\u67e5\u8be2\u8ba1\u5212\u3002<\/li>\n<li><strong>\u6d4b\u8bd5\u548c\u9a8c\u8bc1<\/strong>\uff1a\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\u5b9e\u65bd\u7d22\u5f15\u4e4b\u524d\uff0c\u5728\u6d4b\u8bd5\u73af\u5883\u4e2d\u8fdb\u884c\u6d4b\u8bd5\u548c\u9a8c\u8bc1\uff0c\u786e\u4fdd\u7d22\u5f15\u786e\u5b9e\u80fd\u591f\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3002<\/li>\n<\/ol>\n<p>\u603b\u7684\u6765\u8bf4\uff0c\u662f\u5426\u4f7f\u7528\u7d22\u5f15\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u6027\u80fd\u9700\u6c42\u3002\u901a\u8fc7\u5206\u6790\u548c\u76d1\u63a7\uff0c\u5408\u7406\u5730\u4f7f\u7528\u7d22\u5f15\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6570\u636e\u5e93\u7684\u67e5\u8be2\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u7d22\u5f15\u7684\u9700\u6c42\u5e76\u4e0d\u4e25\u683c\u4f9d\u8d56\u4e8e\u6570\u636e\u91cf\u7684\u5177\u4f53\u5927\u5c0f\uff0c\u800c\u662f\u4f9d\u8d56\u4e8e\u6570\u636e\u8bbf\u95ee\u6a21\u5f0f\u548c\u67e5\u8be2\u6027\u80fd\u9700\u6c42\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u968f\u7740\u6570\u636e\u91cf\u7684\u589e\u52a0&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6354\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[123],"tags":[126,108],"class_list":["post-6354","post","type-post","status-publish","format-standard","hentry","category-123","tag-mysql","tag-108"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6354"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6354\/revisions"}],"predecessor-version":[{"id":6355,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6354\/revisions\/6355"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}