{"id":7084,"date":"2024-11-14T11:47:39","date_gmt":"2024-11-14T03:47:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7084\/"},"modified":"2024-11-14T11:47:39","modified_gmt":"2024-11-14T03:47:39","slug":"mysql-%e6%9f%a5%e8%af%a2%e4%bc%98%e5%8c%96%ef%bc%9a%e5%a6%82%e4%bd%95%e9%ab%98%e6%95%88%e6%9f%a5%e6%89%be%e5%b0%8f%e4%ba%8e%e7%ad%89%e4%ba%8e%e6%8c%87%e5%ae%9a%e6%9c%88%e4%bb%bd%e7%9a%84%e6%9c%80","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7084\/","title":{"rendered":"MySQL \u67e5\u8be2\u4f18\u5316\uff1a\u5982\u4f55\u9ad8\u6548\u67e5\u627e\u5c0f\u4e8e\u7b49\u4e8e\u6307\u5b9a\u6708\u4efd\u7684\u6700\u5927\u6708\u4efd\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173042748496600.jpg\" class=\"aligncenter\" title=\"MySQL \u67e5\u8be2\u4f18\u5316\uff1a\u5982\u4f55\u9ad8\u6548\u67e5\u627e\u5c0f\u4e8e\u7b49\u4e8e\u6307\u5b9a\u6708\u4efd\u7684\u6700\u5927\u6708\u4efd\uff1f\u63d2\u56fe\" alt=\"MySQL \u67e5\u8be2\u4f18\u5316\uff1a\u5982\u4f55\u9ad8\u6548\u67e5\u627e\u5c0f\u4e8e\u7b49\u4e8e\u6307\u5b9a\u6708\u4efd\u7684\u6700\u5927\u6708\u4efd\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u8bbe\u8ba1\uff1a\u67e5\u627e\u5c0f\u4e8e\u7b49\u4e8e\u6307\u5b9a\u6708\u4efd<\/strong><\/p>\n<p>\u7528\u6237\u63d0\u51fa\u4e86\u4e00\u4e2a\u5173\u4e8e mysql \u8868\u67e5\u8be2\u4f18\u5316\u7684\u7684\u95ee\u9898\uff0c\u5176\u4e2d\u6709\u4e00\u4e2a\u540d\u4e3a\u201cnewtable\u201d\u7684\u8868\uff0c\u5305\u542b\u201cmonth\u201d\u5217\u3002\u76ee\u6807\u662f\u67e5\u627e\u5c0f\u4e8e\u6216\u7b49\u4e8e\u6307\u5b9a\u6708\u4efd\uff08\u5728\u672c\u4f8b\u4e2d\u4e3a 9\uff09\u7684\u6700\u5927\u6708\u4efd\u3002\u7528\u6237\u63d0\u51fa\u4e86\u4e24\u79cd\u67e5\u8be2\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd5\u4e00\uff1a<\/strong><\/p>\n<pre>select max(month) from newtabel where month&lt;=9<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5\u4e8c\uff1a<\/strong><\/p>\n<pre>select month from newtabel where month&lt;=9 order by month desc limit 1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u95ee\u9898 1\uff1a\u54ea\u4e2a\u65b9\u6cd5\u66f4\u4f18\uff1f<\/strong><\/p>\n<p>\u7b54\uff1a\u5bf9\u4e8e\u8f83\u5c0f\u89c4\u6a21\u7684\u6570\u636e\u96c6\uff0c\u4e24\u79cd\u65b9\u6cd5\u7684\u6027\u80fd\u53ef\u80fd\u76f8\u4f3c\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0c\u65b9\u6cd5\u4e8c\u66f4\u6709\u6548\u3002\u8fd9\u662f\u56e0\u4e3a\u65b9\u6cd5\u4e8c\u4f7f\u7528\u7d22\u5f15\uff0c\u800c\u65b9\u6cd5\u4e00\u5219\u4e0d\u4f7f\u7528\u3002<\/p>\n<p><strong>\u95ee\u9898 2\uff1a\u662f\u5426\u6709\u66f4\u597d\u7684\u5199\u6cd5\uff1f<\/strong><\/p>\n<p>\u7b54\uff1a\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4fee\u6539\u8fc7\u7684\u67e5\u8be2\uff0c\u5b83\u5229\u7528\u4e86\u7d22\u5f15\u5e76\u51cf\u5c11\u4e86\u6392\u5e8f\u64cd\u4f5c\uff1a<\/p>\n<pre>select month from newtabel where month&lt;=9 order by month desc limit 1 using index (month)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u95ee\u9898 3\uff1a\u5982\u4f55\u8fdb\u884c mysql \u67e5\u8be2\u6d4b\u8bd5\uff1f<\/strong><\/p>\n<p>\u7b54\uff1a\u60a8\u53ef\u4ee5\u4f7f\u7528 mysql \u7684\u201cexpln\u201d\u547d\u4ee4\u5206\u6790\u67e5\u8be2\u6027\u80fd\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528\u5b83\uff1a<\/p>\n<pre>explain select month from newtabel where month&lt;=9 order by month desc limit 1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u663e\u793a\u67e5\u8be2\u7684\u6267\u884c\u8ba1\u5212\uff0c\u5176\u4e2d\u5305\u542b\u4f30\u8ba1\u7684\u6210\u672c\u548c\u8bbf\u95ee\u7684\u65b9\u6cd5\u7b49\u4fe1\u606f\u3002<\/p>\n<p>\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u8bf8\u5982 pt-query-digest \u6216 mysql performance schema \u4e4b\u7c7b\u7684\u5de5\u5177\u6765\u6536\u96c6\u66f4\u9ad8\u7ea7\u7684\u6027\u80fd\u6307\u6807\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u67e5\u8be2\u4f18\u5316\uff1a\u5982\u4f55\u9ad8\u6548\u67e5\u627e\u5c0f\u4e8e\u7b49\u4e8e\u6307\u5b9a\u6708\u4efd\u7684\u6700\u5927\u6708\u4efd\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>\u8bbe\u8ba1\uff1a\u67e5\u627e\u5c0f\u4e8e\u7b49\u4e8e\u6307\u5b9a\u6708\u4efd \u7528\u6237\u63d0\u51fa\u4e86\u4e00\u4e2a\u5173\u4e8e mysql \u8868\u67e5\u8be2\u4f18\u5316\u7684\u7684\u95ee\u9898\uff0c\u5176\u4e2d\u6709\u4e00\u4e2a\u540d\u4e3a\u201cnewtable\u201d\u7684\u8868\uff0c\u5305\u542b\u201cmonth\u201d\u5217\u3002\u76ee\u6807\u662f\u67e5\u627e\u5c0f\u4e8e\u6216\u7b49\u4e8e\u6307\u5b9a\u6708\u4efd\uff08\u5728\u672c\u4f8b\u4e2d\u4e3a 9\uff09\u7684\u6700\u5927\u6708\u4efd\u3002\u7528\u6237\u63d0\u51fa\u4e86\u4e24\u79cd\u67e5\u8be2\u65b9\u6cd5\uff1a \u65b9\u6cd5\u4e00\uff1a select max(month) from newtabel where month&lt;=9 \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5\u4e8c\uff1a select month from newtabel where month&lt;=9 order by month desc limit 1 \u767b\u5f55\u540e\u590d\u5236 \u95ee\u9898 1\uff1a\u54ea\u4e2a\u65b9\u6cd5\u66f4\u4f18\uff1f \u7b54\uff1a\u5bf9\u4e8e\u8f83\u5c0f\u89c4\u6a21\u7684\u6570\u636e\u96c6\uff0c\u4e24\u79cd\u65b9\u6cd5\u7684\u6027\u80fd\u53ef\u80fd\u76f8\u4f3c\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\uff0c\u65b9\u6cd5\u4e8c\u66f4\u6709\u6548\u3002\u8fd9\u662f\u56e0\u4e3a\u65b9\u6cd5\u4e8c\u4f7f\u7528\u7d22\u5f15\uff0c\u800c\u65b9\u6cd5\u4e00\u5219\u4e0d\u4f7f\u7528\u3002 \u95ee\u9898 2\uff1a\u662f\u5426\u6709\u66f4\u597d\u7684\u5199\u6cd5\uff1f \u7b54\uff1a\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4fee\u6539\u8fc7\u7684\u67e5\u8be2\uff0c\u5b83\u5229\u7528\u4e86\u7d22\u5f15\u5e76\u51cf\u5c11\u4e86\u6392\u5e8f\u64cd\u4f5c\uff1a select month from newtabel where month&lt;=9 order by month desc limit 1 using index (month) \u767b\u5f55\u540e\u590d\u5236 \u95ee\u9898 3\uff1a\u5982\u4f55\u8fdb\u884c mysql \u67e5\u8be2\u6d4b\u8bd5\uff1f \u7b54\uff1a\u60a8\u53ef\u4ee5\u4f7f\u7528 mysql [&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-7084","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7084","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=7084"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7084\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}