{"id":27714,"date":"2024-11-24T13:34:05","date_gmt":"2024-11-24T05:34:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27714\/"},"modified":"2024-11-24T13:34:05","modified_gmt":"2024-11-24T05:34:05","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8%e5%a4%9a%e8%a1%a8%e6%9f%a5%e8%af%a2%e4%b8%ad%e8%8e%b7%e5%8f%96%e6%9f%90%e4%b8%aa%e5%85%ac%e5%8f%b8%e7%9a%84%e6%89%80%e6%9c%89%e4%ba%a7%e5%93%81%e7%9a%84%e6%9c%80%e6%96%b0-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27714\/","title":{"rendered":"\u5982\u4f55\u5728\u591a\u8868\u67e5\u8be2\u4e2d\u83b7\u53d6\u67d0\u4e2a\u516c\u53f8\u7684\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u68c0\u6d4b\u62a5\u544a\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173130792382184.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728\u591a\u8868\u67e5\u8be2\u4e2d\u83b7\u53d6\u67d0\u4e2a\u516c\u53f8\u7684\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u68c0\u6d4b\u62a5\u544a\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728\u591a\u8868\u67e5\u8be2\u4e2d\u83b7\u53d6\u67d0\u4e2a\u516c\u53f8\u7684\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u68c0\u6d4b\u62a5\u544a\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728\u591a\u8868\u67e5\u8be2\u4e2d\u83b7\u53d6\u67d0\u4e2a\u516c\u53f8\u7684\u6700\u65b0\u68c0\u6d4b\u62a5\u544a\uff1f<\/strong><\/p>\n<p>\u5728\u591a\u8868\u67e5\u8be2\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u8003\u8651\u5982\u4f55\u4ece\u4e0d\u540c\u8868\u4e2d\u63d0\u53d6\u76f8\u5173\u6570\u636e\u3002\u8003\u8651\u4ee5\u4e0b\u573a\u666f\uff1a<\/p>\n<p>\u6709\u4e24\u5f20\u8868\uff0c\u5206\u522b\u5b58\u50a8\u4ea7\u54c1\u4fe1\u606f\uff08pro\uff09\u548c\u68c0\u6d4b\u4fe1\u606f\uff08procheck\uff09\uff0c\u5176\u4e2d procheck \u4e2d\u7684 pro_id \u4e0e pro \u4e2d\u7684 id \u5173\u8054\uff0c\u6bcf\u4e2a\u4ea7\u54c1\u53ef\u80fd\u5bf9\u5e94\u591a\u4e2a\u68c0\u6d4b\u4fe1\u606f\u8bb0\u5f55\u3002<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u8981\u67e5\u8be2\u67d0\u4e2a\u7279\u5b9a\u516c\u53f8\uff08company_id\uff09\u751f\u4ea7\u7684\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u4e00\u6b21\u68c0\u6d4b\u62a5\u544a\u3002\u867d\u7136\u53ef\u4ee5\u4f7f\u7528\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u67e5\u8be2\uff0c\u4f46\u5b83\u4f1a\u8fd4\u56de\u6240\u6709\u68c0\u6d4b\u62a5\u544a\uff1a<\/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>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e3a\u4e86\u83b7\u53d6\u6700\u65b0\u7684\u68c0\u6d4b\u62a5\u544a\uff0c\u6211\u4eec\u9700\u8981\u8fdb\u4e00\u6b65\u7b5b\u9009\u4fe1\u606f\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u67e5\u8be2 procheck \u8868\u4e2d\u7684\u6bcf\u4e2a\u4ea7\u54c1\u7684\u6700\u65b0 checkdate\uff1a<\/p>\n<pre>select pro_id, max(checkdate) as max_checkdate\nfrom procheck\ngroup by pro_id<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u5c06\u6b64\u7ed3\u679c\u4e0e\u521d\u59cb\u67e5\u8be2\u7684\u8868\uff08\u79f0\u4e3a t1\uff09\u8fdb\u884c\u8fde\u63a5\uff0c\u5e76\u4f7f\u7528 procheck__pro_id \u548c procheck__checkdate \u8fdb\u884c\u5339\u914d\u3002\u6700\u7ec8\u7684\u67e5\u8be2\u5982\u4e0b\uff1a<\/p>\n<pre>SELECT t1.* FROM 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>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u6837\u5c31\u80fd\u5f97\u5230\u67d0\u4e2a\u7279\u5b9a\u516c\u53f8\u751f\u4ea7\u7684\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u4e00\u6b21\u68c0\u6d4b\u62a5\u544a\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728\u591a\u8868\u67e5\u8be2\u4e2d\u83b7\u53d6\u67d0\u4e2a\u516c\u53f8\u7684\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u68c0\u6d4b\u62a5\u544a\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728\u591a\u8868\u67e5\u8be2\u4e2d\u83b7\u53d6\u67d0\u4e2a\u516c\u53f8\u7684\u6700\u65b0\u68c0\u6d4b\u62a5\u544a\uff1f \u5728\u591a\u8868\u67e5\u8be2\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u8003\u8651\u5982\u4f55\u4ece\u4e0d\u540c\u8868\u4e2d\u63d0\u53d6\u76f8\u5173\u6570\u636e\u3002\u8003\u8651\u4ee5\u4e0b\u573a\u666f\uff1a \u6709\u4e24\u5f20\u8868\uff0c\u5206\u522b\u5b58\u50a8\u4ea7\u54c1\u4fe1\u606f\uff08pro\uff09\u548c\u68c0\u6d4b\u4fe1\u606f\uff08procheck\uff09\uff0c\u5176\u4e2d procheck \u4e2d\u7684 pro_id \u4e0e pro \u4e2d\u7684 id \u5173\u8054\uff0c\u6bcf\u4e2a\u4ea7\u54c1\u53ef\u80fd\u5bf9\u5e94\u591a\u4e2a\u68c0\u6d4b\u4fe1\u606f\u8bb0\u5f55\u3002 \u73b0\u5728\u6211\u4eec\u8981\u67e5\u8be2\u67d0\u4e2a\u7279\u5b9a\u516c\u53f8\uff08company_id\uff09\u751f\u4ea7\u7684\u6240\u6709\u4ea7\u54c1\u7684\u6700\u65b0\u4e00\u6b21\u68c0\u6d4b\u62a5\u544a\u3002\u867d\u7136\u53ef\u4ee5\u4f7f\u7528\u7c7b\u4f3c\u4ee5\u4e0b\u7684\u67e5\u8be2\uff0c\u4f46\u5b83\u4f1a\u8fd4\u56de\u6240\u6709\u68c0\u6d4b\u62a5\u544a\uff1a 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 from `da_pro` `pro` left join `da_procheck` `procheck` on `pro`.`id`=`procheck`.`pro_id` where `pro`.`company_id` = 487 \u767b\u5f55\u540e\u590d\u5236 \u4e3a\u4e86\u83b7\u53d6\u6700\u65b0\u7684\u68c0\u6d4b\u62a5\u544a\uff0c\u6211\u4eec\u9700\u8981\u8fdb\u4e00\u6b65\u7b5b\u9009\u4fe1\u606f\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u67e5\u8be2 procheck \u8868\u4e2d\u7684\u6bcf\u4e2a\u4ea7\u54c1\u7684\u6700\u65b0 checkdate\uff1a select pro_id, max(checkdate) as max_checkdate from procheck group by pro_id \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\uff0c\u6211\u4eec\u5c06\u6b64\u7ed3\u679c\u4e0e\u521d\u59cb\u67e5\u8be2\u7684\u8868\uff08\u79f0\u4e3a t1\uff09\u8fdb\u884c\u8fde\u63a5\uff0c\u5e76\u4f7f\u7528 procheck__pro_id \u548c procheck__checkdate \u8fdb\u884c\u5339\u914d\u3002\u6700\u7ec8\u7684\u67e5\u8be2\u5982\u4e0b\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-27714","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27714","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=27714"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27714\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}