{"id":5291,"date":"2024-11-14T13:10:49","date_gmt":"2024-11-14T05:10:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5291\/"},"modified":"2024-11-14T13:10:49","modified_gmt":"2024-11-14T05:10:49","slug":"mysql%e6%80%8e%e4%b9%88%e6%a0%b7%e6%9f%a5%e8%af%a2%e4%b8%8b%e4%b8%80%e6%9d%a1%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5291\/","title":{"rendered":"mysql\u600e\u4e48\u6837\u67e5\u8be2\u4e0b\u4e00\u6761\u8bb0\u5f55"},"content":{"rendered":"<blockquote><p>\n  \u53ef\u4ee5\u901a\u8fc7 limit \u548c offset \u5b50\u53e5\u67e5\u8be2\u4e0b\u4e00\u6761\u8bb0\u5f55\uff1a\u4f7f\u7528 limit 1 \u6307\u5b9a\u8fd4\u56de\u4e00\u6761\u8bb0\u5f55\uff1b\u4f7f\u7528 offset n \u6307\u5b9a\u8df3\u8fc7\u7684\u8bb0\u5f55\u6570\uff08n \u4e3a\u4e0a\u4e00\u6761\u8bb0\u5f55\u7684 id\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/26\/2024052618311444079.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u6837\u67e5\u8be2\u4e0b\u4e00\u6761\u8bb0\u5f55\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u6837\u67e5\u8be2\u4e0b\u4e00\u6761\u8bb0\u5f55\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u4e0b\u4e00\u6761\u8bb0\u5f55<\/strong><\/p>\n<p>\u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 LIMIT \u548c OFFSET \u5b50\u53e5\u6765\u67e5\u8be2\u4e0b\u4e00\u6761\u8bb0\u5f55\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>SELECT *\nFROM table_name\nLIMIT 1\nOFFSET n;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>n \u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u8bb0\u5f55\u6570\u3002<\/li>\n<li>1 \u6307\u5b9a\u8981\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a users \u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4ee5\u4e0b\u8bb0\u5f55\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Mary<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Bob<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Alice<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8981\u83b7\u53d6 John\uff08id \u4e3a 1\uff09\u4e4b\u540e\u7684\u4e0b\u4e00\u6761\u8bb0\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT *\nFROM users\nLIMIT 1\nOFFSET 1;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e2a\u67e5\u8be2\u5c06\u8fd4\u56de\u4ee5\u4e0b\u7ed3\u679c\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>Mary<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u53ef\u89c1\uff0c\u8be5\u67e5\u8be2\u8df3\u8fc7\u4e86\u4e00\u6761\u8bb0\u5f55\uff08John\uff09\uff0c\u5e76\u8fd4\u56de\u4e86\u4e0b\u4e00\u6761\u8bb0\u5f55\uff08Mary\uff09\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u6837\u67e5\u8be2\u4e0b\u4e00\u6761\u8bb0\u5f55\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>\u53ef\u4ee5\u901a\u8fc7 limit \u548c offset \u5b50\u53e5\u67e5\u8be2\u4e0b\u4e00\u6761\u8bb0\u5f55\uff1a\u4f7f\u7528 limit 1 \u6307\u5b9a\u8fd4\u56de\u4e00\u6761\u8bb0\u5f55\uff1b\u4f7f\u7528 offset n \u6307\u5b9a\u8df3\u8fc7\u7684\u8bb0\u5f55\u6570\uff08n \u4e3a\u4e0a\u4e00\u6761\u8bb0\u5f55\u7684 id\uff09\u3002 \u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u4e0b\u4e00\u6761\u8bb0\u5f55 \u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 LIMIT \u548c OFFSET \u5b50\u53e5\u6765\u67e5\u8be2\u4e0b\u4e00\u6761\u8bb0\u5f55\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a SELECT * FROM table_name LIMIT 1 OFFSET n; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a n \u6307\u5b9a\u8981\u8df3\u8fc7\u7684\u8bb0\u5f55\u6570\u3002 1 \u6307\u5b9a\u8981\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u3002 \u793a\u4f8b \u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a users \u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4ee5\u4e0b\u8bb0\u5f55\uff1a id name 1 John 2 Mary 3 Bob 4 Alice \u8981\u83b7\u53d6 John\uff08id \u4e3a 1\uff09\u4e4b\u540e\u7684\u4e0b\u4e00\u6761\u8bb0\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a [&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-5291","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5291","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=5291"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5291\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}