{"id":200617,"date":"2025-05-06T11:07:13","date_gmt":"2025-05-06T03:07:13","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200617\/"},"modified":"2025-05-06T11:07:13","modified_gmt":"2025-05-06T03:07:13","slug":"%e5%9c%a8-mysql-%e4%b8%ad%ef%bc%8cupdate-join-%e8%af%ad%e5%8f%a5%e4%b8%ad%e4%bd%bf%e7%94%a8-order-by-%e4%bc%9a%e5%af%bc%e8%87%b4%e4%bb%80%e4%b9%88%e9%97%ae%e9%a2%98%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200617\/","title":{"rendered":"\u5728 MySQL \u4e2d\uff0c`update join` \u8bed\u53e5\u4e2d\u4f7f\u7528 `order by` \u4f1a\u5bfc\u81f4\u4ec0\u4e48\u95ee\u9898\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5728 MySQL \u4e2d\uff0c`update join` \u8bed\u53e5\u4e2d\u4f7f\u7528 `order by` \u4f1a\u5bfc\u81f4\u4ec0\u4e48\u95ee\u9898\uff1f<\/h1>\n<p>\u73cd\u60dc\u65f6\u95f4\uff0c\u52e4\u594b\u5b66\u4e60\uff01\u4eca\u5929\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u6b63\u6587\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\u7b49\u7b49\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\uff0c\u6216\u8005\u662f\u5bf9\u6709\u7591\u95ee\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u6211\uff01\u540e\u9762\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u5185\u5bb9\u7684\uff0c\u5e0c\u671b\u90fd\u80fd\u5e2e\u5230\u6b63\u5728\u5b66\u4e60\u7684\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241109\/1731161205672f6c752d1ab.jpg\" class=\"aligncenter\"><\/p>\n<h2>\u5728 mysql \u4e2d\uff0cupdate join \u8bed\u53e5\u4e2d\u5305\u542b order by \u4f1a\u5bfc\u81f4 mysql \u5d29\u6e83\u5417\uff1f<\/h2>\n<h3>\u95ee\u9898<\/h3>\n<p>\u5728\u4f7f\u7528 update join \u8bed\u53e5\u65f6\uff0c\u52a0\u5165 order by \u4f1a\u5bfc\u81f4 mysql \u5d29\u6e83\u3002\u539f\u56e0\u4e0d\u660e\uff0c\u6c42\u52a9\u5927\u795e\u3002<\/p>\n<h3>\u5efa\u8868\u8bed\u53e5<\/h3>\n<pre>-- `lebon-infra-dev`.cfg_dev_network_push_status definition\n\ncreate table `cfg_dev_network_push_status` (\n  `id` bigint not null auto_increment comment '\u6d41\u6c34\u53f7  | \u4e0eid\u4e3a\u540c\u4e00\u5b57\u6bb5\uff0c\u81ea\u589e\u6570\u5217',\n  `task_id` varchar(16) not null comment '\u4efb\u52a1id',\n  `push_status` char(1) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '0' comment '\u63a8\u9001\u72b6\u6001(0:\u5f85\u63a8\u9001\/1:\u5df2\u63a8\u9001\/2:\u5df2\u53d6\u6d88)',\n  `push_plan_time` char(14) character set utf8mb4 collate utf8mb4_0900_ai_ci not null comment '\u9884\u7ea6\u63a8\u9001\u65f6\u95f4\uff08yyyymmddhhmmss\uff09',\n  `push_type` char(1) not null comment '\u63a8\u9001\u79cd\u7c7b(1:\u63a8\u9001\u914d\u7f6e\u9879\/2:\u63a8\u9001\u4f18\u5148\u5ea6\/3:\u63a8\u9001\u91cd\u542f\u547d\u4ee4)',\n  `dev_id` varchar(32) not null comment '\u8bbe\u5907id',\n  `config_group_id` varchar(16) not null comment '\u914d\u7f6e\u7ec4id',\n  `config_item_id` varchar(16) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '' comment '\u914d\u7f6e\u9879id',\n  `push_begin_time` char(17) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '00000000000000000' comment '\u63a8\u9001\u5f00\u59cb\u65f6\u95f4\uff08yyyymmddhhmmssfff\uff09',\n  `push_end_time` char(17) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '00000000000000000' comment '\u63a8\u9001\u7ed3\u675f\u65f6\u95f4\uff08yyyymmddhhmmssfff\uff09',\n  `push_duration_s` int not null default '0' comment '\u63a8\u9001\u8017\u65f6',\n  `push_result` char(1) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '' comment '\u63a8\u9001\u7ed3\u679c0:\u6210\u529f\/1:\u5931\u8d25',\n  `fail_reason` varchar(128) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '' comment '\u5931\u8d25\u539f\u56e0',\n  `push_retry_times` int not null default '0' comment '\u91cd\u8bd5\u6b21\u6570',\n  `remark` varchar(256) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '' comment '\u5907\u6ce8',\n  `del_flag` char(1) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '0' comment '\u5220\u9664\u72b6\u6001',\n  `version` int not null default '0' comment '\u7248\u672c\u9501',\n  `create_by` varchar(32) character set utf8mb4 collate utf8mb4_0900_ai_ci not null comment '\u521b\u5efa\u4eba',\n  `create_time` datetime not null comment '\u521b\u5efa\u65f6\u95f4',\n  `update_by` varchar(32) character set utf8mb4 collate utf8mb4_0900_ai_ci default null comment '\u66f4\u65b0\u4eba',\n  `update_time` datetime default null comment '\u66f4\u65b0\u65f6\u95f4',\n  primary key (`id`),\n  unique key `cfg_dev_network_push_status_un` (`id`) using btree\n) engine=innodb auto_increment=149 default charset=utf8mb4 collate=utf8mb4_0900_ai_ci comment='\u914d\u7f6e-\u7ec8\u7aef\u7f51\u7edc\u914d\u7f6e\u63a8\u9001\u72b6\u6001';\n\n-- `lebon-infra-dev`.cfg_dev_network_bind_status definition\n\ncreate table `cfg_dev_network_bind_status` (\n  `id` bigint not null auto_increment comment '\u4efb\u52a1id | \u4e0eid\u4e3a\u540c\u4e00\u5b57\u6bb5\uff0c\u81ea\u589e\u6570\u5217',\n  `dev_id` varchar(32) not null comment '\u8bbe\u5907id',\n  `config_group_id` varchar(16) not null comment '\u914d\u7f6e\u7ec4id',\n  `config_group_name` varchar(32) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '' comment '\u914d\u7f6e\u7ec4\u540d',\n  `status` char(1) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '0' comment '\u72b6\u6001',\n  `push_plan_time` char(14) character set utf8mb4 collate utf8mb4_0900_ai_ci not null comment '\u9884\u7ea6\u63a8\u9001\u65f6\u95f4(yyyymmddhhmmss)',\n  `push_begin_time` char(17) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '00000000000000000' comment '\u63a8\u9001\u5f00\u59cb\u65f6\u95f4(yyyymmddhhmmssfff)',\n  `push_end_time` char(17) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '00000000000000000' comment '\u63a8\u9001\u7ed3\u675f\u65f6\u95f4(yyyymmddhhmmssfff)',\n  `push_duration_s` int not null default '0' comment '\u63a8\u9001\u8017\u65f6',\n  `effective_time` char(17) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '00000000000000000' comment '\u5b9e\u9645\u751f\u6548\u65f6\u95f4(yyyymmddhhmmssfff)',\n  `invalid_time` char(17) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '00000000000000000' comment '\u5b9e\u9645\u5931\u6548\u65f6\u95f4(yyyymmddhhmmssfff)',\n  `fail_reason` varchar(128) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '' comment '\u5931\u8d25\u539f\u56e0',\n  `cancel_reason` varchar(128) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '' comment '\u53d6\u6d88\u539f\u56e0',\n  `operator` varchar(32) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '' comment '\u64cd\u4f5c\u8005',\n  `remark` varchar(256) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '' comment '\u5907\u6ce8',\n  `version` int not null default '0' comment '\u7248\u672c\u9501',\n  `del_flag` char(1) character set utf8mb4 collate utf8mb4_0900_ai_ci not null default '0' comment '\u5220\u9664\u72b6\u6001',\n  `create_by` varchar(32) character set utf8mb4 collate utf8mb4_0900_ai_ci not null comment '\u521b\u5efa\u4eba',\n  `create_time` datetime not null comment '\u521b\u5efa\u65f6\u95f4',\n  `update_by` varchar(32) character set utf8mb4 collate utf8mb4_0900_ai_ci default null comment '\u66f4\u65b0\u4eba',\n  `update_time` datetime default null comment '\u66f4\u65b0\u65f6\u95f4',\n  primary key (`id`) using btree,\n  unique key `cfg_dev_network_bind_status_un` (`id`) using btree\n) engine=innodb auto_increment=1070 default charset=utf8mb4 collate=utf8mb4_0900_ai_ci comment='\u914d\u7f6e-\u7ec8\u7aef\u7f51\u7edc\u914d\u7f6e\u7ed1\u5b9a\u72b6\u6001';<\/pre>\n<h3>\u7b54\u6848<\/h3>\n<p>\u5728 mysql \u4e2d\uff0c<strong>update join<\/strong> \u8bed\u53e5\u4e2d\u4e0d\u5141\u8bb8\u5305\u542b <strong>order by<\/strong>\uff0c\u5426\u5219\u4f1a\u62a5\u9519 incorrect usage of update and order by\u3002<\/p>\n<h3>\u539f\u56e0<\/h3>\n<p><strong>update join<\/strong> \u8bed\u53e5\u7684\u542b\u4e49\u662f\u66f4\u65b0\u52a0\u5165\u53e6\u4e00\u4e2a\u8868\u4e2d\u6ee1\u8db3\u6761\u4ef6\u7684\u884c\u3002\u5f53\u4f7f\u7528 <strong>order by<\/strong> \u65f6\uff0cmysql \u65e0\u6cd5\u786e\u5b9a\u54ea\u4e2a\u884c\u5e94\u8be5\u88ab\u66f4\u65b0\u3002<\/p>\n<h3>\u89e3\u51b3\u65b9\u6848<\/h3>\n<p>\u8981\u907f\u514d\u6b64\u9519\u8bef\uff0c\u53ef\u4ee5\u5c06 <strong>order by<\/strong> \u79fb\u5230\u5b50\u67e5\u8be2\u6216\u4f7f\u7528\u7b1b\u5361\u5c14\u4e58\u79ef\uff1a<\/p>\n<pre>update\n    cfg_dev_network_push_status\nset\n    push_retry_times = push_retry_times + 1,<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u4e3b\u673a\u5b9d\u8d1d\uff01\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 MySQL \u4e2d\uff0c`updat&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200617","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200617"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200617\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}