{"id":6433,"date":"2024-11-14T14:59:10","date_gmt":"2024-11-14T06:59:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6433\/"},"modified":"2024-11-14T14:59:10","modified_gmt":"2024-11-14T06:59:10","slug":"mysql%e5%88%86%e9%a1%b5%e5%ae%9e%e7%8e%b0%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6433\/","title":{"rendered":"mysql\u5206\u9875\u5b9e\u73b0\u539f\u7406"},"content":{"rendered":"<blockquote><p>\n  mysql \u5206\u9875\u901a\u8fc7\u4f7f\u7528 limit \u548c offset \u5b50\u53e5\u5b9e\u73b0\uff0climit \u6307\u5b9a\u8981\u8fd4\u56de\u7684\u884c\u6570\uff0coffset \u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u884c\u6570\u3002\u5206\u9875\u8fc7\u7a0b\u5305\u62ec\u786e\u5b9a\u9875\u6570\u3001offset \u503c\u548c limit \u503c\uff0c\u7136\u540e\u4f7f\u7528 limit \u548c offset \u5b50\u53e5\u7f16\u5199\u67e5\u8be2\u3002\u4f8b\u5982\uff0c\u83b7\u53d6\u7b2c 2 \u9875\uff08\u6bcf\u9875 10 \u884c\uff09\u5c31\u4f7f\u7528 select * from table_name limit 10 offset 10; \u67e5\u8be2\uff0c\u8be5\u67e5\u8be2\u8fd4\u56de\u7b2c 11 \u81f3 20 \u884c\u7684\u8bb0\u5f55\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/02\/2024080217555923533.jpg\" class=\"aligncenter\" title=\"mysql\u5206\u9875\u5b9e\u73b0\u539f\u7406\u63d2\u56fe\" alt=\"mysql\u5206\u9875\u5b9e\u73b0\u539f\u7406\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5206\u9875\u5b9e\u73b0\u539f\u7406<\/strong><\/p>\n<p>\u5206\u9875\u662f\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\u4e00\u9879\u91cd\u8981\u7684\u529f\u80fd\uff0c\u5b83\u5141\u8bb8\u7528\u6237\u5c06\u5927\u578b\u6570\u636e\u96c6\u5212\u5206\u4e3a\u8f83\u5c0f\u3001\u66f4\u6613\u4e8e\u7ba1\u7406\u7684\u9875\u9762\u3002\u5728 MySQL \u4e2d\uff0c\u5206\u9875\u901a\u8fc7\u4f7f\u7528 LIMIT \u548c OFFSET \u5b50\u53e5\u5b9e\u73b0\u3002<\/p>\n<p><strong>LIMIT \u548c OFFSET<\/strong><\/p>\n<ul>\n<li> <strong>LIMIT<\/strong> \u6307\u5b9a\u8981\u8fd4\u56de\u7684\u884c\u6570\u3002<\/li>\n<li> <strong>OFFSET<\/strong> \u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u884c\u6570\uff08\u4ece\u5f00\u5934\u7684\u8ba1\u6570\uff09\u3002<\/li>\n<\/ul>\n<p>\u8bed\u6cd5\uff1a<\/p>\n<pre>SELECT * FROM table_name LIMIT number OFFSET offset_value;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5206\u9875\u8fc7\u7a0b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 LIMIT \u548c OFFSET \u5b9e\u73b0\u5206\u9875\uff1a<\/p>\n<ol>\n<li>\u786e\u5b9a\u8981\u663e\u793a\u7684\u9875\u6570\uff0c\u4f8b\u5982\u7b2c 2 \u9875\u3002<\/li>\n<li>\u786e\u5b9a\u4ece\u7b2c\u51e0\u884c\u5f00\u59cb\uff08OFFSET\uff09\u3002\u5bf9\u4e8e\u7b2c 2 \u9875\uff0cOFFSET \u503c\u4e3a (\u9875\u6570 &#8211; 1) * \u6bcf\u9875\u884c\u6570\uff0c\u5373 (2 &#8211; 1) * 10\uff0c\u5373 10\u3002<\/li>\n<li>\u786e\u5b9a\u8981\u663e\u793a\u7684\u884c\u6570\uff08LIMIT\uff09\u3002\u5bf9\u4e8e\u7b2c 2 \u9875\uff0cLIMIT \u503c\u4e3a\u6bcf\u9875\u884c\u6570\uff0c\u5373 10\u3002<\/li>\n<li>\u4f7f\u7528 LIMIT \u548c OFFSET \u5b50\u53e5\u7f16\u5199\u67e5\u8be2\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<pre>SELECT * FROM table_name LIMIT 10 OFFSET 10;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6848\u4f8b<\/strong><\/p>\n<p>\u8003\u8651\u4e00\u4e2a\u6709 50 \u884c\u8bb0\u5f55\u7684\u8868 my_table\u3002\u8981\u83b7\u53d6\u7b2c 2 \u9875\uff08\u6bcf\u9875 10 \u884c\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT * FROM my_table LIMIT 10 OFFSET 10;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u8fd4\u56de\u7b2c 11 \u81f3 20 \u884c\u7684\u8bb0\u5f55\uff0c\u4ece\u800c\u5728\u7b2c 2 \u9875\u4e0a\u663e\u793a\u6570\u636e\u3002<\/p>\n<p><strong>\u4f18\u70b9<\/strong><\/p>\n<ul>\n<li> <strong>\u6613\u4e8e\u4f7f\u7528\uff1a<\/strong>LIMIT \u548c OFFSET \u5b50\u53e5\u4f7f\u7528\u7b80\u5355\uff0c\u6613\u4e8e\u7406\u89e3\u3002<\/li>\n<li> <strong>\u6548\u7387\uff1a<\/strong>\u5f53\u4e0e\u7d22\u5f15\u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u5206\u9875\u53ef\u4ee5\u9ad8\u6548\u5730\u67e5\u627e\u7279\u5b9a\u7684\u6570\u636e\u5757\u3002<\/li>\n<\/ul>\n<p><strong>\u7f3a\u70b9<\/strong><\/p>\n<ul>\n<li> <strong>\u6570\u636e\u79fb\u52a8\uff1a<\/strong>\u5728\u4f7f\u7528\u504f\u79fb\u91cf\u65f6\uff0cMySQL \u53ef\u80fd\u9700\u8981\u79fb\u52a8\u6570\u636e\u5757\uff0c\u8fd9\u4f1a\u5f71\u54cd\u6027\u80fd\u3002<\/li>\n<li> <strong>\u4e0d\u9002\u5408\u5927\u504f\u91cf\uff1a<\/strong>\u5f53 OFFSET \u503c\u975e\u5e38\u5927\u65f6\uff0c\u6027\u80fd\u4f1a\u5927\u5927\u964d\u4f4e\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5206\u9875\u5b9e\u73b0\u539f\u7406\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 \u5206\u9875\u901a\u8fc7\u4f7f\u7528 limit \u548c offset \u5b50\u53e5\u5b9e\u73b0\uff0climit \u6307\u5b9a\u8981\u8fd4\u56de\u7684\u884c\u6570\uff0coffset \u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u884c\u6570\u3002\u5206\u9875\u8fc7\u7a0b\u5305\u62ec\u786e\u5b9a\u9875\u6570\u3001offset \u503c\u548c limit \u503c\uff0c\u7136\u540e\u4f7f\u7528 limit \u548c offset \u5b50\u53e5\u7f16\u5199\u67e5\u8be2\u3002\u4f8b\u5982\uff0c\u83b7\u53d6\u7b2c 2 \u9875\uff08\u6bcf\u9875 10 \u884c\uff09\u5c31\u4f7f\u7528 select * from table_name limit 10 offset 10; \u67e5\u8be2\uff0c\u8be5\u67e5\u8be2\u8fd4\u56de\u7b2c 11 \u81f3 20 \u884c\u7684\u8bb0\u5f55\u3002 MySQL \u5206\u9875\u5b9e\u73b0\u539f\u7406 \u5206\u9875\u662f\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\u4e00\u9879\u91cd\u8981\u7684\u529f\u80fd\uff0c\u5b83\u5141\u8bb8\u7528\u6237\u5c06\u5927\u578b\u6570\u636e\u96c6\u5212\u5206\u4e3a\u8f83\u5c0f\u3001\u66f4\u6613\u4e8e\u7ba1\u7406\u7684\u9875\u9762\u3002\u5728 MySQL \u4e2d\uff0c\u5206\u9875\u901a\u8fc7\u4f7f\u7528 LIMIT \u548c OFFSET \u5b50\u53e5\u5b9e\u73b0\u3002 LIMIT \u548c OFFSET LIMIT \u6307\u5b9a\u8981\u8fd4\u56de\u7684\u884c\u6570\u3002 OFFSET \u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u884c\u6570\uff08\u4ece\u5f00\u5934\u7684\u8ba1\u6570\uff09\u3002 \u8bed\u6cd5\uff1a SELECT * FROM table_name LIMIT number [&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-6433","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6433","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=6433"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6433\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}