{"id":5160,"date":"2024-11-14T12:28:00","date_gmt":"2024-11-14T04:28:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5160\/"},"modified":"2024-11-14T12:28:00","modified_gmt":"2024-11-14T04:28:00","slug":"mysql%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e5%88%86%e9%a1%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5160\/","title":{"rendered":"mysql\u600e\u4e48\u5b9e\u73b0\u5206\u9875"},"content":{"rendered":"<blockquote><p>\n  \u5728 mysql \u4e2d\u5b9e\u73b0\u5206\u9875\uff0c\u53ef\u4ee5\u4f7f\u7528 limit \u548c offset \u5b50\u53e5\u3002limit \u5b50\u53e5\u6307\u5b9a\u8fd4\u56de\u7684\u884c\u6570\uff0c\u800c offset \u5b50\u53e5\u6307\u5b9a\u8df3\u8fc7\u7684\u884c\u6570\u3002\u4f7f\u7528\u6b65\u9aa4\u4e3a\uff1a1. \u786e\u5b9a\u6bcf\u9875\u884c\u6570\uff1b2. \u786e\u5b9a\u5f53\u524d\u9875\u7801\uff1b3. \u8ba1\u7b97\u504f\u79fb\u91cf\u4e3a (\u5f53\u524d\u9875\u7801 &#8211; 1) * \u884c\u6570\uff1b4. \u4f7f\u7528 limit \u548c offset \u5b50\u53e5\u4ece\u8868\u4e2d\u9009\u62e9\u884c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/22\/2024052217482535077.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u5b9e\u73b0\u5206\u9875\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u5b9e\u73b0\u5206\u9875\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 MySQL \u5b9e\u73b0\u5206\u9875<\/strong><\/p>\n<p>\u5206\u9875\u662f\u5c06\u5927\u91cf\u6570\u636e\u5206\u6210\u8f83\u5c0f\u3001\u66f4\u6613\u4e8e\u7ba1\u7406\u7684\u5757\u7684\u8fc7\u7a0b\u3002\u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 LIMIT \u548c OFFSET \u5b50\u53e5\u5b9e\u73b0\u5206\u9875\u3002<\/p>\n<p><strong>LIMIT \u5b50\u53e5\uff1a<\/strong><br \/>LIMIT \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u8981\u4ece\u67e5\u8be2\u4e2d\u8fd4\u56de\u7684\u884c\u6570\u3002\u8bed\u6cd5\u4e3a\uff1a<\/p>\n<pre>LIMIT [\u504f\u79fb\u91cf,] \u884c\u6570<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u67e5\u8be2\u5c06\u8fd4\u56de\u4ece\u7b2c 10 \u884c\u5f00\u59cb\u7684 10 \u884c\u6570\u636e\uff1a<\/p>\n<pre>SELECT * FROM table_name LIMIT 10 OFFSET 10;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>OFFSET \u5b50\u53e5\uff1a<\/strong><br \/>OFFSET \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u5728\u8fd4\u56de\u884c\u4e4b\u524d\u8981\u8df3\u8fc7\u7684\u884c\u6570\u3002\u8bed\u6cd5\u4e3a\uff1a<\/p>\n<pre>OFFSET \u504f\u79fb\u91cf<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0cOFFSET 10 \u8868\u793a\u5728\u8fd4\u56de\u884c\u4e4b\u524d\u8df3\u8fc7\u524d 10 \u884c\u3002<\/p>\n<p><strong>\u4f7f\u7528 OFFSET \u548c LIMIT \u8fdb\u884c\u5206\u9875\uff1a<\/strong><br \/>\u8981\u4f7f\u7528 OFFSET \u548c LIMIT \u8fdb\u884c\u5206\u9875\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u786e\u5b9a\u6bcf\u9875\u8981\u663e\u793a\u7684\u884c\u6570\uff08\u884c\u6570\uff09\u3002<\/li>\n<li>\u786e\u5b9a\u5f53\u524d\u9875\u7801\uff08\u504f\u79fb\u91cf\uff09\u3002\u504f\u79fb\u91cf\u7b49\u4e8e (\u5f53\u524d\u9875\u7801 &#8211; 1) * \u884c\u6570\u3002<\/li>\n<li>\u4f7f\u7528 LIMIT \u548c OFFSET \u5b50\u53e5\u4ece\u8868\u4e2d\u9009\u62e9\u884c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/li>\n<\/ol>\n<pre>SELECT * FROM table_name LIMIT \u884c\u6570 OFFSET \u504f\u79fb\u91cf;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u4ece\u8868\u4e2d\u83b7\u53d6\u7b2c 3 \u9875\uff0c\u6bcf\u9875\u663e\u793a 10 \u884c\uff0c\u5219\u67e5\u8be2\u5c06\u4e3a\uff1a<\/p>\n<pre>SELECT * FROM table_name LIMIT 10 OFFSET 20;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u672a\u6307\u5b9a\u504f\u79fb\u91cf\uff0c\u5219\u9ed8\u8ba4\u4e3a 0\uff0c\u8868\u793a\u4ece\u7b2c 1 \u884c\u5f00\u59cb\u3002<\/li>\n<li>LIMIT \u548c OFFSET \u5b50\u53e5\u53ef\u4ee5\u5355\u72ec\u4f7f\u7528\u6216\u7ec4\u5408\u4f7f\u7528\u3002<\/li>\n<li>LIMIT \u5b50\u53e5\u4ec5\u6307\u5b9a\u8981\u8fd4\u56de\u7684\u884c\u6570\uff0c\u800c OFFSET \u5b50\u53e5\u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u884c\u6570\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5b9e\u73b0\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\u5b9e\u73b0\u5206\u9875\uff0c\u53ef\u4ee5\u4f7f\u7528 limit \u548c offset \u5b50\u53e5\u3002limit \u5b50\u53e5\u6307\u5b9a\u8fd4\u56de\u7684\u884c\u6570\uff0c\u800c offset \u5b50\u53e5\u6307\u5b9a\u8df3\u8fc7\u7684\u884c\u6570\u3002\u4f7f\u7528\u6b65\u9aa4\u4e3a\uff1a1. \u786e\u5b9a\u6bcf\u9875\u884c\u6570\uff1b2. \u786e\u5b9a\u5f53\u524d\u9875\u7801\uff1b3. \u8ba1\u7b97\u504f\u79fb\u91cf\u4e3a (\u5f53\u524d\u9875\u7801 &#8211; 1) * \u884c\u6570\uff1b4. \u4f7f\u7528 limit \u548c offset \u5b50\u53e5\u4ece\u8868\u4e2d\u9009\u62e9\u884c\u3002 \u5982\u4f55\u4f7f\u7528 MySQL \u5b9e\u73b0\u5206\u9875 \u5206\u9875\u662f\u5c06\u5927\u91cf\u6570\u636e\u5206\u6210\u8f83\u5c0f\u3001\u66f4\u6613\u4e8e\u7ba1\u7406\u7684\u5757\u7684\u8fc7\u7a0b\u3002\u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 LIMIT \u548c OFFSET \u5b50\u53e5\u5b9e\u73b0\u5206\u9875\u3002 LIMIT \u5b50\u53e5\uff1aLIMIT \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u8981\u4ece\u67e5\u8be2\u4e2d\u8fd4\u56de\u7684\u884c\u6570\u3002\u8bed\u6cd5\u4e3a\uff1a LIMIT [\u504f\u79fb\u91cf,] \u884c\u6570 \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u4ee5\u4e0b\u67e5\u8be2\u5c06\u8fd4\u56de\u4ece\u7b2c 10 \u884c\u5f00\u59cb\u7684 10 \u884c\u6570\u636e\uff1a SELECT * FROM table_name LIMIT 10 OFFSET 10; \u767b\u5f55\u540e\u590d\u5236 OFFSET [&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-5160","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5160","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=5160"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5160\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}