{"id":5482,"date":"2024-11-14T10:10:33","date_gmt":"2024-11-14T02:10:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5482\/"},"modified":"2024-11-14T10:10:33","modified_gmt":"2024-11-14T02:10:33","slug":"mysql%e6%9f%a5%e8%af%a2%e8%af%ad%e5%8f%a5%e6%80%8e%e4%b9%88%e5%88%86%e9%a1%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5482\/","title":{"rendered":"mysql\u67e5\u8be2\u8bed\u53e5\u600e\u4e48\u5206\u9875"},"content":{"rendered":"<blockquote><p>\n  \u5728 mysql \u4e2d\u4f7f\u7528 limit \u548c offset \u5173\u952e\u5b57\u8fdb\u884c\u5206\u9875\uff0c\u8bed\u6cd5\u4e3a\uff1aselect * from table_name limit offset, limit\u3002offset \u6307\u5b9a\u8df3\u8fc7\u7684\u884c\u6570\uff0climit \u6307\u5b9a\u68c0\u7d22\u7684\u884c\u6570\u3002\u793a\u4f8b\uff1alimit 10, 5 \u4ece\u7b2c 10 \u884c\u5f00\u59cb\u68c0\u7d22 5 \u884c\u6570\u636e\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6e38\u6807\u3001\u4e34\u65f6\u8868\u548c\u5206\u533a\u8868\u7b49\u65b9\u6cd5\u8fdb\u884c\u5206\u9875\uff0c\u5e76\u5efa\u8bae\u4f7f\u7528\u7d22\u5f15\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052903362379264.jpg\" class=\"aligncenter\" title=\"mysql\u67e5\u8be2\u8bed\u53e5\u600e\u4e48\u5206\u9875\u63d2\u56fe\" alt=\"mysql\u67e5\u8be2\u8bed\u53e5\u600e\u4e48\u5206\u9875\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u67e5\u8be2\u8bed\u53e5\u5206\u9875<\/strong><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u8bed\u53e5\u8fdb\u884c\u5206\u9875\uff1f<\/strong><\/p>\n<p>\u5728 MySQL \u4e2d\uff0c\u4f7f\u7528 LIMIT \u548c OFFSET \u5173\u952e\u5b57\u8fdb\u884c\u5206\u9875\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 \u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u884c\u6570\u3002<\/li>\n<li>limit \u6307\u5b9a\u8981\u68c0\u7d22\u7684\u884c\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u68c0\u7d22\u4ece\u7b2c 10 \u884c\u5f00\u59cb\u7684 5 \u884c\u6570\u636e\uff1a<\/p>\n<pre>SELECT * FROM table_name LIMIT 10, 5;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>LIMIT \u548c OFFSET \u5fc5\u987b\u540c\u65f6\u4f7f\u7528\u3002<\/li>\n<li>OFFSET \u7684\u503c\u5fc5\u987b\u4e3a\u975e\u8d1f\u6574\u6570\u3002<\/li>\n<li>LIMIT \u7684\u503c\u5fc5\u987b\u4e3a\u6b63\u6574\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u5206\u9875\u65b9\u6cd5<\/strong><\/p>\n<p>\u9664\u4e86\u4f7f\u7528 LIMIT \u548c OFFSET \u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\u8fdb\u884c\u5206\u9875\uff1a<\/p>\n<ul>\n<li> <strong>\u6e38\u6807\uff08Cursors\uff09\uff1a<\/strong>\u5141\u8bb8\u60a8\u9010\u884c\u904d\u5386\u7ed3\u679c\u96c6\u3002<\/li>\n<li> <strong>\u4e34\u65f6\u8868\uff1a<\/strong>\u5c06\u67e5\u8be2\u7ed3\u679c\u5b58\u50a8\u5728\u4e34\u65f6\u8868\u4e2d\uff0c\u7136\u540e\u5bf9\u4e34\u65f6\u8868\u8fdb\u884c\u5206\u9875\u3002<\/li>\n<li> <strong>\u5206\u533a\u8868\uff1a<\/strong>\u5c06\u6570\u636e\u8868\u5212\u5206\u4e3a\u66f4\u5c0f\u7684\u5206\u533a\uff0c\u4ece\u800c\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u8fdb\u884c\u5206\u9875\u3002<\/li>\n<\/ul>\n<p><strong>\u6700\u4f73\u5b9e\u8df5<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u7d22\u5f15\u6765\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u3002<\/li>\n<li>\u4f7f\u7528 LIMIT \u548c OFFSET \u5e76\u5217\u8fdb\u884c\u5206\u9875\u3002<\/li>\n<li>\u8003\u8651\u4f7f\u7528\u5176\u4ed6\u5206\u9875\u65b9\u6cd5\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u67e5\u8be2\u8bed\u53e5\u600e\u4e48\u5206\u9875\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>\u5728 mysql \u4e2d\u4f7f\u7528 limit \u548c offset \u5173\u952e\u5b57\u8fdb\u884c\u5206\u9875\uff0c\u8bed\u6cd5\u4e3a\uff1aselect * from table_name limit offset, limit\u3002offset \u6307\u5b9a\u8df3\u8fc7\u7684\u884c\u6570\uff0climit \u6307\u5b9a\u68c0\u7d22\u7684\u884c\u6570\u3002\u793a\u4f8b\uff1alimit 10, 5 \u4ece\u7b2c 10 \u884c\u5f00\u59cb\u68c0\u7d22 5 \u884c\u6570\u636e\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6e38\u6807\u3001\u4e34\u65f6\u8868\u548c\u5206\u533a\u8868\u7b49\u65b9\u6cd5\u8fdb\u884c\u5206\u9875\uff0c\u5e76\u5efa\u8bae\u4f7f\u7528\u7d22\u5f15\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u3002 MySQL \u67e5\u8be2\u8bed\u53e5\u5206\u9875 \u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u8bed\u53e5\u8fdb\u884c\u5206\u9875\uff1f \u5728 MySQL \u4e2d\uff0c\u4f7f\u7528 LIMIT \u548c OFFSET \u5173\u952e\u5b57\u8fdb\u884c\u5206\u9875\uff1a SELECT * FROM table_name LIMIT offset, limit; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a offset \u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u884c\u6570\u3002 limit \u6307\u5b9a\u8981\u68c0\u7d22\u7684\u884c\u6570\u3002 \u793a\u4f8b\uff1a \u4ee5\u4e0b\u793a\u4f8b\u68c0\u7d22\u4ece\u7b2c 10 \u884c\u5f00\u59cb\u7684 5 \u884c\u6570\u636e\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-5482","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5482","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=5482"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5482\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}