{"id":6324,"date":"2024-11-14T11:10:04","date_gmt":"2024-11-14T03:10:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6324\/"},"modified":"2024-11-14T11:10:04","modified_gmt":"2024-11-14T03:10:04","slug":"mysql%e5%88%86%e9%a1%b5%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6324\/","title":{"rendered":"mysql\u5206\u9875\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  mysql\u5206\u9875\u67e5\u8be2\u901a\u8fc7\u504f\u79fb\u548c\u9650\u5236\u5b50\u53e5\u5c06\u6570\u636e\u96c6\u5212\u5206\u4e3a\u8f83\u5c0f\u7684\u5b50\u96c6\uff1a1.\u8ba1\u7b97\u504f\u79fb\u91cf\uff1a\u504f\u79fb\u91cf=(\u9875\u7801-1)\u5206\u9875\u5927\u5c0f\u30022.\u9650\u5236\u7ed3\u679c\uff1alimit\u5206\u9875\u5927\u5c0f\u30023.\u7ec4\u88c5\u67e5\u8be2\uff1aselect from table order by column limit \u5206\u9875\u5927\u5c0f offset \u504f\u79fb\u91cf\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202407\/31\/2024073122403849913.jpg\" class=\"aligncenter\" title=\"mysql\u5206\u9875\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"mysql\u5206\u9875\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7f16\u5199 MySQL \u5206\u9875\u67e5\u8be2<\/strong><\/p>\n<p>MySQL \u5206\u9875\u67e5\u8be2\u7528\u4e8e\u5c06\u5927\u91cf\u6570\u636e\u96c6\u5212\u5206\u4e3a\u8f83\u5c0f\u7684\u5b50\u96c6\uff0c\u4ee5\u4fbf\u4e00\u6b21\u8f7b\u677e\u5904\u7406\u3002\u5b83\u5728\u663e\u793a\u641c\u7d22\u7ed3\u679c\u3001\u5206\u9875\u5217\u8868\u548c\u5206\u6bb5\u52a0\u8f7d\u6570\u636e\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p><strong>\u7f16\u5199\u5206\u9875\u67e5\u8be2\u7684\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u8ba1\u7b97\u504f\u79fb\u91cf\uff1a<\/strong>\u504f\u79fb\u91cf\u51b3\u5b9a\u4ece\u7ed3\u679c\u96c6\u4e2d\u8df3\u8fc7\u591a\u5c11\u884c\u3002\u516c\u5f0f\u4e3a\uff1a\u504f\u79fb\u91cf = (\u9875\u7801 &#8211; 1) * \u5206\u9875\u5927\u5c0f<\/li>\n<li> <strong>\u9650\u5236\u7ed3\u679c\uff1a<\/strong>LIMIT \u5b50\u53e5\u7528\u4e8e\u9650\u5236\u8fd4\u56de\u7684\u884c\u6570\u3002\u516c\u5f0f\u4e3a\uff1aLIMIT \u5206\u9875\u5927\u5c0f<\/li>\n<li> <strong>\u7ec4\u88c5\u67e5\u8be2\uff1a<\/strong>\u5c06\u504f\u79fb\u91cf\u548c\u9650\u5236\u5b50\u53e5\u6dfb\u52a0\u5230\u539f\u59cb\u67e5\u8be2\u4e2d\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/li>\n<\/ol>\n<pre>SELECT * FROM table\nORDER BY column\nLIMIT \u5206\u9875\u5927\u5c0f OFFSET \u504f\u79fb\u91cf;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u8981\u4ece\u5305\u542b 1000 \u884c\u7684\u8868\u4e2d\u63d0\u53d6\u7b2c 2 \u9875\uff0c\u6bcf\u9875\u663e\u793a 10 \u884c\uff0c\u67e5\u8be2\u5e94\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>SELECT * FROM table\nORDER BY column\nLIMIT 10 OFFSET 10;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4ed6\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u4f7f\u7528\u7d22\u5f15\uff1a<\/strong>\u5728\u6392\u5e8f\u5217\u4e0a\u521b\u5efa\u7d22\u5f15\u53ef\u4ee5\u663e\u7740\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3002<\/li>\n<li> <strong>\u4f18\u5316\u5b50\u67e5\u8be2\uff1a<\/strong>\u5982\u679c\u67e5\u8be2\u5305\u542b\u5b50\u67e5\u8be2\uff0c\u8bf7\u5c1d\u8bd5\u5c06\u5176\u91cd\u5199\u4e3a\u8054\u63a5\u6216\u6d3e\u751f\u8868\u3002<\/li>\n<li> <strong>\u8003\u8651\u4f7f\u7528\u6e38\u6807\uff1a<\/strong>\u5bf9\u4e8e\u975e\u5e38\u5927\u7684\u6570\u636e\u96c6\uff0c\u6e38\u6807\u53ef\u4ee5\u63d0\u4f9b\u66f4\u6709\u6548\u7684\u5206\u9875\u673a\u5236\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u5206\u9875\u6846\u67b6\uff1a<\/strong>\u8bb8\u591a\u7f16\u7a0b\u6846\u67b6\u548c ORM \u63d0\u4f9b\u5185\u7f6e\u7684\u5206\u9875\u529f\u80fd\uff0c\u4f7f\u7f16\u5199\u5206\u9875\u67e5\u8be2\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5206\u9875\u600e\u4e48\u5199\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\u67e5\u8be2\u901a\u8fc7\u504f\u79fb\u548c\u9650\u5236\u5b50\u53e5\u5c06\u6570\u636e\u96c6\u5212\u5206\u4e3a\u8f83\u5c0f\u7684\u5b50\u96c6\uff1a1.\u8ba1\u7b97\u504f\u79fb\u91cf\uff1a\u504f\u79fb\u91cf=(\u9875\u7801-1)\u5206\u9875\u5927\u5c0f\u30022.\u9650\u5236\u7ed3\u679c\uff1alimit\u5206\u9875\u5927\u5c0f\u30023.\u7ec4\u88c5\u67e5\u8be2\uff1aselect from table order by column limit \u5206\u9875\u5927\u5c0f offset \u504f\u79fb\u91cf\u3002 \u5982\u4f55\u7f16\u5199 MySQL \u5206\u9875\u67e5\u8be2 MySQL \u5206\u9875\u67e5\u8be2\u7528\u4e8e\u5c06\u5927\u91cf\u6570\u636e\u96c6\u5212\u5206\u4e3a\u8f83\u5c0f\u7684\u5b50\u96c6\uff0c\u4ee5\u4fbf\u4e00\u6b21\u8f7b\u677e\u5904\u7406\u3002\u5b83\u5728\u663e\u793a\u641c\u7d22\u7ed3\u679c\u3001\u5206\u9875\u5217\u8868\u548c\u5206\u6bb5\u52a0\u8f7d\u6570\u636e\u65f6\u975e\u5e38\u6709\u7528\u3002 \u7f16\u5199\u5206\u9875\u67e5\u8be2\u7684\u6b65\u9aa4\uff1a \u8ba1\u7b97\u504f\u79fb\u91cf\uff1a\u504f\u79fb\u91cf\u51b3\u5b9a\u4ece\u7ed3\u679c\u96c6\u4e2d\u8df3\u8fc7\u591a\u5c11\u884c\u3002\u516c\u5f0f\u4e3a\uff1a\u504f\u79fb\u91cf = (\u9875\u7801 &#8211; 1) * \u5206\u9875\u5927\u5c0f \u9650\u5236\u7ed3\u679c\uff1aLIMIT \u5b50\u53e5\u7528\u4e8e\u9650\u5236\u8fd4\u56de\u7684\u884c\u6570\u3002\u516c\u5f0f\u4e3a\uff1aLIMIT \u5206\u9875\u5927\u5c0f \u7ec4\u88c5\u67e5\u8be2\uff1a\u5c06\u504f\u79fb\u91cf\u548c\u9650\u5236\u5b50\u53e5\u6dfb\u52a0\u5230\u539f\u59cb\u67e5\u8be2\u4e2d\uff0c\u5982\u4e0b\u6240\u793a\uff1a SELECT * FROM table ORDER BY column LIMIT \u5206\u9875\u5927\u5c0f OFFSET \u504f\u79fb\u91cf; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a \u8981\u4ece\u5305\u542b 1000 \u884c\u7684\u8868\u4e2d\u63d0\u53d6\u7b2c 2 \u9875\uff0c\u6bcf\u9875\u663e\u793a 10 \u884c\uff0c\u67e5\u8be2\u5e94\u5982\u4e0b\u6240\u793a\uff1a SELECT * FROM table ORDER BY column LIMIT [&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-6324","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6324","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=6324"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6324\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}