{"id":200999,"date":"2025-05-06T10:00:56","date_gmt":"2025-05-06T02:00:56","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200999\/"},"modified":"2025-05-06T10:00:56","modified_gmt":"2025-05-06T02:00:56","slug":"%e5%a6%82%e4%bd%95%e6%9f%a5%e8%af%a2%e7%89%b9%e5%ae%9a%e5%85%ac%e5%8f%b8%e6%89%80%e6%9c%89%e4%ba%a7%e5%93%81%e7%9a%84%e6%9c%80%e6%96%b0%e4%b8%80%e6%ac%a1%e6%a3%80%e6%b5%8b%e6%8a%a5%e5%91%8a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200999\/","title":{"rendered":"\u5982\u4f55\u67e5\u8be2\u7279\u5b9a\u516c\u53f8\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u4e00\u6b21\u68c0\u6d4b\u62a5\u544a\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u67e5\u8be2\u7279\u5b9a\u516c\u53f8\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u4e00\u6b21\u68c0\u6d4b\u62a5\u544a\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241125\/17324935586743c0f688e0f.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u591a\u8868\u67e5\u8be2\uff1a\u83b7\u53d6\u7279\u5b9a\u516c\u53f8\u4ea7\u54c1\u7684\u6700\u65b0\u4e00\u6b21\u68c0\u6d4b\u62a5\u544a<\/strong><\/p>\n<p>\u5728\u4e24\u4e2a\u8868\u76f8\u4e92\u5173\u8054\u7684\u60c5\u51b5\u4e0b\uff0c\u6709\u65f6\u9700\u8981\u67e5\u8be2\u591a\u5f20\u8868\u4ee5\u83b7\u53d6\u6240\u9700\u6570\u636e\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u6709\u4e24\u5f20\u8868\uff1a\u4ea7\u54c1\u4fe1\u606f\u8868\uff08pro\uff09\u548c\u68c0\u6d4b\u4fe1\u606f\u8868\uff08procheck\uff09\uff0c\u5176\u4e2d procheck \u8868\u4e2d\u7684 pro_id \u4e0e pro \u8868\u4e2d\u7684 id \u5173\u8054\u3002\u6bcf\u4e2a\u4ea7\u54c1\u53ef\u80fd\u6709\u591a\u4e2a\u68c0\u6d4b\u8bb0\u5f55\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5982\u4f55\u67e5\u8be2\u67d0\u4e2a\u7279\u5b9a\u516c\u53f8\uff08pro \u8868\u4e2d\u7684 company_id\uff09\u751f\u4ea7\u7684\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u4e00\u6b21\u68c0\u6d4b\u62a5\u544a\uff1f<\/p>\n<p><strong>\u793a\u4f8b\u67e5\u8be2\uff1a<\/strong><\/p>\n<pre>select `pro`.`id`,`pro`.`pm`,`pro`.`company_id`,procheck.id as procheck__id,procheck.pro_id as procheck__pro_id,procheck.checkdate as procheck__checkdate \nfrom `da_pro` `pro` \nleft join `da_procheck` `procheck` on `pro`.`id`=`procheck`.`pro_id` \nwhere `pro`.`company_id` = 487<\/pre>\n<p>\u7136\u800c\uff0c\u6b64\u67e5\u8be2\u8fd4\u56de\u4e86\u8be5\u516c\u53f8\u7684\u6240\u6709\u68c0\u6d4b\u8bb0\u5f55\uff0c\u800c\u4e0d\u662f\u6309\u4ea7\u54c1\u5206\u7ec4\u7684\u6700\u65b0\u8bb0\u5f55\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u83b7\u53d6\u6700\u65b0\u8bb0\u5f55\uff0c\u9700\u8981\u4f7f\u7528\u5b50\u67e5\u8be2\u6765\u8bc6\u522b\u6bcf\u4e2a\u4ea7\u54c1\u5bf9\u5e94\u7684\u6700\u65b0\u68c0\u6d4b\u65e5\u671f\u3002\u7136\u540e\uff0c\u5c06\u6b64\u5b50\u67e5\u8be2\u4e0e\u539f\u59cb\u67e5\u8be2\u8fde\u63a5\u8d77\u6765\uff0c\u4ee5\u7b5b\u9009\u51fa\u6700\u65b0\u65e5\u671f\u7684\u8bb0\u5f55\u3002<\/p>\n<p><strong>\u4fee\u6b63\u540e\u7684\u67e5\u8be2\uff1a<\/strong><\/p>\n<pre>(\u4f60\u7684 SQL \u8bed\u53e5) t1\nJOIN (\n    SELECT pro_id, MAX(checkdate) AS max_checkdate\n    FROM procheck\n    GROUP BY pro_id\n) t2\nON t1.procheck__pro_id = t2.pro_id AND t1.procheck__checkdate = t2.max_checkdate;<\/pre>\n<p>\u6b64\u67e5\u8be2\u5c06\u8fd4\u56de\u6bcf\u4e2a\u4ea7\u54c1\u7684\u6700\u65b0\u68c0\u6d4b\u62a5\u544a\uff0c\u6ee1\u8db3\u7279\u5b9a\u516c\u53f8\uff08company_id = 487\uff09\u7684\u8fc7\u6ee4\u6761\u4ef6\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u67e5\u8be2\u7279\u5b9a\u516c\u53f8\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u4e00\u6b21\u68c0\u6d4b\u62a5\u544a\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u67e5\u8be2\u7279\u5b9a\u516c\u53f8\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u4e00&#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-200999","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200999","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=200999"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200999\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}