{"id":5124,"date":"2024-11-14T08:16:15","date_gmt":"2024-11-14T00:16:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5124\/"},"modified":"2024-11-14T08:16:15","modified_gmt":"2024-11-14T00:16:15","slug":"mysql%e6%80%8e%e4%b9%88%e7%94%a8%e5%88%86%e9%a1%b5%e6%9f%a5%e8%af%a2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5124\/","title":{"rendered":"mysql\u600e\u4e48\u7528\u5206\u9875\u67e5\u8be2"},"content":{"rendered":"<blockquote><p>\n  mysql \u4e2d\u7684\u5206\u9875\u67e5\u8be2\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a\u786e\u5b9a\u8981\u67e5\u8be2\u7684\u9875\u9762\u548c\u6bcf\u9875\u5927\u5c0f\u3002\u8ba1\u7b97\u504f\u79fb\u91cf\uff1a\u504f\u79fb\u91cf = (\u9875\u9762\u53f7 &#8211; 1) * \u6bcf\u9875\u5927\u5c0f\u3002\u4f7f\u7528 limit \u5b50\u53e5\uff1aselect * from table_name limit offset, limit;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/22\/2024052215003544838.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u7528\u5206\u9875\u67e5\u8be2\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u7528\u5206\u9875\u67e5\u8be2\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4f7f\u7528 MySQL \u8fdb\u884c\u5206\u9875\u67e5\u8be2<\/strong><\/p>\n<p>MySQL \u4e2d\u7684\u5206\u9875\u67e5\u8be2\u7528\u4e8e\u4ece\u5927\u578b\u6570\u636e\u96c6\u68c0\u7d22\u7279\u5b9a\u9875\u9762\u6216\u5b50\u96c6\u7684\u6570\u636e\uff0c\u5728\u5904\u7406\u6d77\u91cf\u6570\u636e\u65f6\u975e\u5e38\u6709\u7528\u3002\u5206\u9875\u67e5\u8be2\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<p><strong>1. \u786e\u5b9a\u8981\u67e5\u8be2\u7684\u9875\u9762\u548c\u6bcf\u9875\u7684\u5927\u5c0f<\/strong><\/p>\n<p>\u9700\u8981\u786e\u5b9a\u8981\u68c0\u7d22\u7684\u9875\u9762\u53f7\uff08\u4f8b\u5982\u7b2c 5 \u9875\uff09\u4ee5\u53ca\u6bcf\u9875\u663e\u793a\u7684\u884c\u6570\uff08\u4f8b\u5982 10\uff09\u3002<\/p>\n<p><strong>2. \u8ba1\u7b97\u504f\u79fb\u91cf<\/strong><\/p>\n<p>\u504f\u79fb\u91cf\u662f\u6307\u67e5\u8be2\u4e2d\u8df3\u8fc7\u7684\u6570\u636e\u884c\u6570\uff0c\u5b83\u7531\u4ee5\u4e0b\u516c\u5f0f\u8ba1\u7b97\uff1a<\/p>\n<p>\u504f\u79fb\u91cf = (\u9875\u9762\u53f7 &#8211; 1) * \u6bcf\u9875\u5927\u5c0f<\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u68c0\u7d22\u7b2c 5 \u9875\u4e14\u6bcf\u9875\u5927\u5c0f\u4e3a 10\uff0c\u5219\u504f\u79fb\u91cf\u4e3a (5 &#8211; 1) * 10 = 40\u3002<\/p>\n<p><strong>3. \u4f7f\u7528 LIMIT \u5b50\u53e5<\/strong><\/p>\n<p>LIMIT \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u67e5\u8be2\u7ed3\u679c\u7684\u884c\u6570\u9650\u5236\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>SELECT * FROM table_name LIMIT offset, limit;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>offset \u662f\u504f\u79fb\u91cf\uff0c\u7528\u4e8e\u8df3\u8fc7\u6307\u5b9a\u884c\u6570\u3002<\/li>\n<li>limit \u662f\u6bcf\u9875\u8981\u663e\u793a\u7684\u884c\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\u67e5\u8be2<\/strong><\/p>\n<pre>SELECT * FROM customers LIMIT 40, 10;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u67e5\u8be2\u5c06\u4ece\u540d\u4e3a customers \u7684\u8868\u4e2d\u68c0\u7d22\u7b2c 5 \u9875\uff08\u8df3\u8fc7 40 \u884c\uff09\u7684\u6570\u636e\uff0c\u6bcf\u9875\u663e\u793a 10 \u884c\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u504f\u79fb\u91cf\u5e94\u59cb\u7ec8\u4e3a\u6b63\u6574\u6570\u3002<\/li>\n<li>\u504f\u79fb\u91cf\u52a0\u6bcf\u9875\u5927\u5c0f\u4e0d\u5e94\u8be5\u8d85\u8fc7\u6570\u636e\u96c6\u7684\u603b\u884c\u6570\u3002<\/li>\n<li>\u5982\u679c\u504f\u79fb\u91cf\u5927\u4e8e\u6570\u636e\u96c6\u7684\u5927\u5c0f\uff0c\u5219\u67e5\u8be2\u5c06\u8fd4\u56de\u7a7a\u7ed3\u679c\u96c6\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u7528\u5206\u9875\u67e5\u8be2\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>mysql \u4e2d\u7684\u5206\u9875\u67e5\u8be2\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a\u786e\u5b9a\u8981\u67e5\u8be2\u7684\u9875\u9762\u548c\u6bcf\u9875\u5927\u5c0f\u3002\u8ba1\u7b97\u504f\u79fb\u91cf\uff1a\u504f\u79fb\u91cf = (\u9875\u9762\u53f7 &#8211; 1) * \u6bcf\u9875\u5927\u5c0f\u3002\u4f7f\u7528 limit \u5b50\u53e5\uff1aselect * from table_name limit offset, limit; \u4f7f\u7528 MySQL \u8fdb\u884c\u5206\u9875\u67e5\u8be2 MySQL \u4e2d\u7684\u5206\u9875\u67e5\u8be2\u7528\u4e8e\u4ece\u5927\u578b\u6570\u636e\u96c6\u68c0\u7d22\u7279\u5b9a\u9875\u9762\u6216\u5b50\u96c6\u7684\u6570\u636e\uff0c\u5728\u5904\u7406\u6d77\u91cf\u6570\u636e\u65f6\u975e\u5e38\u6709\u7528\u3002\u5206\u9875\u67e5\u8be2\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a 1. \u786e\u5b9a\u8981\u67e5\u8be2\u7684\u9875\u9762\u548c\u6bcf\u9875\u7684\u5927\u5c0f \u9700\u8981\u786e\u5b9a\u8981\u68c0\u7d22\u7684\u9875\u9762\u53f7\uff08\u4f8b\u5982\u7b2c 5 \u9875\uff09\u4ee5\u53ca\u6bcf\u9875\u663e\u793a\u7684\u884c\u6570\uff08\u4f8b\u5982 10\uff09\u3002 2. \u8ba1\u7b97\u504f\u79fb\u91cf \u504f\u79fb\u91cf\u662f\u6307\u67e5\u8be2\u4e2d\u8df3\u8fc7\u7684\u6570\u636e\u884c\u6570\uff0c\u5b83\u7531\u4ee5\u4e0b\u516c\u5f0f\u8ba1\u7b97\uff1a \u504f\u79fb\u91cf = (\u9875\u9762\u53f7 &#8211; 1) * \u6bcf\u9875\u5927\u5c0f \u4f8b\u5982\uff0c\u8981\u68c0\u7d22\u7b2c 5 \u9875\u4e14\u6bcf\u9875\u5927\u5c0f\u4e3a 10\uff0c\u5219\u504f\u79fb\u91cf\u4e3a (5 &#8211; 1) * 10 = 40\u3002 3. \u4f7f\u7528 LIMIT \u5b50\u53e5 LIMIT \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u67e5\u8be2\u7ed3\u679c\u7684\u884c\u6570\u9650\u5236\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a SELECT [&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-5124","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5124","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=5124"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5124\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}