{"id":6405,"date":"2024-08-21T11:34:33","date_gmt":"2024-08-21T02:34:33","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=6405"},"modified":"2024-05-25T13:46:39","modified_gmt":"2024-05-25T04:46:39","slug":"post-6405","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/6405","title":{"rendered":"MySQL\u3067ROW_NUMBER\u95a2\u6570\u3092\u4f7f\u7528\u3057\u3066\u30b0\u30eb\u30fc\u30d7\u6bce\u306b\u9023\u756a\u3092\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u4ee5\u524d\u306b<a href=\"https:\/\/taitan916.info\/blog\/archives\/3202\" target=\"_blank\" rel=\"noopener\">MySQL\u3067\u30aa\u30fc\u30c8\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u3092\u4f7f\u7528\u305b\u305a\u306b\u30b0\u30eb\u30fc\u30d7\u6bce\u306b\u9023\u756a\u3092\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5<\/a>\u3092\u30e1\u30e2\u3057\u305f\u304c\u3001MySQL8\u7cfb\u304b\u3089\u306fROW_NUMBER\u95a2\u6570\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u3082\u3063\u3068\u7c21\u5358\u306b\u63a1\u756a\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3089\u3057\u3044\u3002\u4ee5\u4e0b\u306b\u5229\u7528\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/h2>\n<h3>ROW_NUMBER\u95a2\u6570<\/h3>\n<p><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/ja\/window-function-descriptions.html#function_row-number\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/ja\/window-function-descriptions.html#function_row-number<\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>\u30c6\u30fc\u30d6\u30eb\u5185\u5bb9\u306b\u3064\u3044\u3066<\/h2>\n<p>\u4ee5\u524d\u306b\u53d6\u5f97\u3057\u305f<a href=\"https:\/\/taitan916.info\/blog\/archives\/3277\" target=\"_blank\" rel=\"noopener\">\u5168\u56fd\u306e\u5e02\u533a\u753a\u6751\u306e\u30c7\u30fc\u30bf<\/a>\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n<p>\u6771\u4eac\u90fd(ken_id=13)\u306e\u30c7\u30fc\u30bf\u4e14\u3064id\u3067\u30bd\u30fc\u30c8\u3057\u305f\u3044\u5834\u5408\u4ee5\u4e0b\u306e\u3088\u3046\u306aSQL\u6587\u306b\u306a\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SELECT `id`, ROW_NUMBER() OVER (ORDER BY `ken_id`) AS row_num, `ken_name`, `city_name`\r\nFROM `ad_address` \r\nWHERE `ken_id` = 13 \r\nLIMIT 10;<\/pre>\n<p>\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">+-----------+---------+-----------+-----------+\r\n| id        | row_num | ken_name  | city_name |\r\n+-----------+---------+-----------+-----------+\r\n| 150614700 |       1 | \u6771\u4eac\u90fd    | \u6e0b\u8c37\u533a    |\r\n| 150619000 |       2 | \u6771\u4eac\u90fd    | \u6e0b\u8c37\u533a    |\r\n| 150800100 |       3 | \u6771\u4eac\u90fd    | \u6e0b\u8c37\u533a    |\r\n| 150801000 |       4 | \u6771\u4eac\u90fd    | \u6e0b\u8c37\u533a    |\r\n| 150801500 |       5 | \u6771\u4eac\u90fd    | \u6e0b\u8c37\u533a    |\r\n| 150801900 |       6 | \u6771\u4eac\u90fd    | \u6e0b\u8c37\u533a    |\r\n| 150808100 |       7 | \u6771\u4eac\u90fd    | \u6e0b\u8c37\u533a    |\r\n| 150830100 |       8 | \u6771\u4eac\u90fd    | \u6e0b\u8c37\u533a    |\r\n| 150830300 |       9 | \u6771\u4eac\u90fd    | \u6e0b\u8c37\u533a    |\r\n| 150830600 |      10 | \u6771\u4eac\u90fd    | \u6e0b\u8c37\u533a    |\r\n+-----------+---------+-----------+-----------+\r\n10 rows in set (0.93 sec)<\/pre>\n<p>\u30da\u30fc\u30b8\u30f3\u30b0\u306b\u5bfe\u5fdc\u3055\u305b\u305f\u3044\u5834\u5408\u3001\u901a\u5e38\u901a\u308aOFFSET\u3092\u3064\u3051\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SELECT `id`, ROW_NUMBER() OVER (ORDER BY `id`) AS row_num, `ken_name`, `city_name`\r\nFROM `ad_address` \r\nWHERE `ken_id` = 13 \r\nLIMIT 10, 10;<\/pre>\n<p>\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">+-----------+---------+-----------+--------------+\r\n| id        | row_num | ken_name  | city_name    |\r\n+-----------+---------+-----------+--------------+\r\n| 100001400 |      11 | \u6771\u4eac\u90fd    | \u5343\u4ee3\u7530\u533a     |\r\n| 100010000 |      12 | \u6771\u4eac\u90fd    | \u5927\u5cf6\u753a       |\r\n| 100010100 |      13 | \u6771\u4eac\u90fd    | \u5927\u5cf6\u753a       |\r\n| 100010200 |      14 | \u6771\u4eac\u90fd    | \u5927\u5cf6\u753a       |\r\n| 100010300 |      15 | \u6771\u4eac\u90fd    | \u5927\u5cf6\u753a       |\r\n| 100010400 |      16 | \u6771\u4eac\u90fd    | \u5927\u5cf6\u753a       |\r\n| 100021100 |      17 | \u6771\u4eac\u90fd    | \u5927\u5cf6\u753a       |\r\n| 100021200 |      18 | \u6771\u4eac\u90fd    | \u5927\u5cf6\u753a       |\r\n| 100030100 |      19 | \u6771\u4eac\u90fd    | \u5229\u5cf6\u6751       |\r\n| 100040000 |      20 | \u6771\u4eac\u90fd    | \u65b0\u5cf6\u6751       |\r\n+-----------+---------+-----------+--------------+\r\n10 rows in set (1.09 sec)<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u6240\u611f<\/h2>\n<p><a href=\"https:\/\/taitan916.info\/blog\/archives\/3202\" target=\"_blank\" rel=\"noopener\">MySQL\u306e\u5909\u6570\u3092\u4f7f\u3046\u65b9\u6cd5<\/a>\u3088\u308a\u5206\u304b\u308a\u3084\u3059\u3044\u3088\u3046\u306b\u601d\u3063\u305f\u3002\u4eca\u5f8c\u306f\u3053\u3061\u3089\u306e\u65b9\u6cd5\u3092\u4f7f\u7528\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u3053\u308d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u524d\u306bMySQL\u3067\u30aa\u30fc\u30c8\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u3092\u4f7f\u7528\u305b\u305a\u306b\u30b0\u30eb\u30fc\u30d7\u6bce\u306b\u9023\u756a\u3092\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5 ... <\/p>\n","protected":false},"author":1,"featured_media":1072,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5,66],"tags":[],"class_list":["post-6405","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","category-database"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=6405"}],"version-history":[{"count":1,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6405\/revisions"}],"predecessor-version":[{"id":6406,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/6405\/revisions\/6406"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1072"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=6405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=6405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=6405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}