{"id":7265,"date":"2024-11-14T12:32:20","date_gmt":"2024-11-14T04:32:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7265\/"},"modified":"2024-11-14T12:32:20","modified_gmt":"2024-11-14T04:32:20","slug":"mysql-5-7-%e5%ad%90%e6%9f%a5%e8%af%a2%e6%8e%92%e5%ba%8f%ef%bc%9a%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e5%90%8c%e4%b8%80%e7%94%a8%e6%88%b7%e5%90%8c%e4%b8%80%e4%ba%a7%e5%93%81%e6%97%b6%e9%97%b4%e6%9c%80","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7265\/","title":{"rendered":"MySQL 5.7 \u5b50\u67e5\u8be2\u6392\u5e8f\uff1a\u5982\u4f55\u83b7\u53d6\u540c\u4e00\u7528\u6237\u540c\u4e00\u4ea7\u54c1\u65f6\u95f4\u6700\u65b0\u7684\u8bb0\u5f55\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173064209846727.jpg\" class=\"aligncenter\" title=\"MySQL 5.7 \u5b50\u67e5\u8be2\u6392\u5e8f\uff1a\u5982\u4f55\u83b7\u53d6\u540c\u4e00\u7528\u6237\u540c\u4e00\u4ea7\u54c1\u65f6\u95f4\u6700\u65b0\u7684\u8bb0\u5f55\uff1f\u63d2\u56fe\" alt=\"MySQL 5.7 \u5b50\u67e5\u8be2\u6392\u5e8f\uff1a\u5982\u4f55\u83b7\u53d6\u540c\u4e00\u7528\u6237\u540c\u4e00\u4ea7\u54c1\u65f6\u95f4\u6700\u65b0\u7684\u8bb0\u5f55\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5b50\u67e5\u8be2\u6392\u5e8f\u95ee\u9898\u89e3\u51b3<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u60f3\u8981\u5b9e\u73b0\u540c\u4e00\u7528\u6237\u540c\u4e00\u4ea7\u54c1\u53ea\u663e\u793a\u65f6\u95f4\u6700\u65b0\u7684\u8bb0\u5f55\uff0c\u4f46\u5728\u4f7f\u7528\u5b50\u67e5\u8be2\u6392\u5e8f\u540e\uff0c\u7ed3\u679c\u5374\u4e0d\u6b63\u786e\u3002<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u7531\u4e8e\u4f7f\u7528\u7684\u6570\u636e\u5e93\u7248\u672c\u662f5.7\uff0c\u65e0\u6cd5\u4f7f\u7528\u7a97\u53e3\u51fd\u6570\u6765\u5b9e\u73b0\u6b64\u9700\u6c42\u3002\u4e0b\u9762\u63d0\u4f9b\u4e00\u4e2a\u7248\u672c\u517c\u5bb9\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p><strong>\u5b50\u67e5\u8be2\u5173\u8054<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u4f7f\u7528\u5b50\u67e5\u8be2\u8ba1\u7b97\u6bcf\u4e2a\u5206\u7ec4\uff08user_id\u3001product_id\uff09\u7684 create_time\u6700\u5927\u503c\u3002\u63a5\u7740\uff0c\u5c06\u8be5\u5b50\u67e5\u8be2\u4e0e\u539f\u8868\u5173\u8054\uff0c\u6761\u4ef6\u4e3a user_id\u3001product_id \u76f8\u7b49\uff0c\u4e14 create_time \u4e3a\u6700\u5927\u503c\u3002<\/p>\n<p><strong>\u6539\u8fdb\u540e\u7684\uff1a<\/strong><\/p>\n<pre>select t2.id, t1.*\nfrom (\n    select max(create_time) as create_time, user_id, product_id\n    from demo\n    group by user_id, product_id\n) t1\nleft join demo t2\non t1.user_id = t2.user_id\nand t1.product_id = t2.product_id\nand t1.create_time = t2.create_time<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n<ul>\n<li>\u5b50\u67e5\u8be2 t1 \u8ba1\u7b97\u6bcf\u4e2a\u5206\u7ec4\u7684 create_time \u6700\u5927\u503c\u3002<\/li>\n<li>\u5916\u67e5\u8be2\u5173\u8054 t1 \u548c\u539f\u8868 t2\uff0c\u6761\u4ef6\u4e3a user_id\u3001product_id \u76f8\u7b49\uff0c\u4e14 create_time \u4e3a\u6700\u5927\u503c\u3002<\/li>\n<li>\u6700\u7ec8\u7684\u67e5\u8be2\u7ed3\u679c\u4e3a\u6ee1\u8db3\u4e0a\u8ff0\u6761\u4ef6\u7684\u8bb0\u5f55\uff0c\u5373\u540c\u4e00\u7528\u6237\u540c\u4e00\u4ea7\u54c1\u4e2d create_time \u6700\u65b0\u7684\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL 5.7 \u5b50\u67e5\u8be2\u6392\u5e8f\uff1a\u5982\u4f55\u83b7\u53d6\u540c\u4e00\u7528\u6237\u540c\u4e00\u4ea7\u54c1\u65f6\u95f4\u6700\u65b0\u7684\u8bb0\u5f55\uff1f\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>\u5b50\u67e5\u8be2\u6392\u5e8f\u95ee\u9898\u89e3\u51b3 \u95ee\u9898\uff1a \u60f3\u8981\u5b9e\u73b0\u540c\u4e00\u7528\u6237\u540c\u4e00\u4ea7\u54c1\u53ea\u663e\u793a\u65f6\u95f4\u6700\u65b0\u7684\u8bb0\u5f55\uff0c\u4f46\u5728\u4f7f\u7528\u5b50\u67e5\u8be2\u6392\u5e8f\u540e\uff0c\u7ed3\u679c\u5374\u4e0d\u6b63\u786e\u3002 \u56de\u7b54\uff1a \u7531\u4e8e\u4f7f\u7528\u7684\u6570\u636e\u5e93\u7248\u672c\u662f5.7\uff0c\u65e0\u6cd5\u4f7f\u7528\u7a97\u53e3\u51fd\u6570\u6765\u5b9e\u73b0\u6b64\u9700\u6c42\u3002\u4e0b\u9762\u63d0\u4f9b\u4e00\u4e2a\u7248\u672c\u517c\u5bb9\u7684\u89e3\u51b3\u65b9\u6848\uff1a \u5b50\u67e5\u8be2\u5173\u8054 \u9996\u5148\uff0c\u4f7f\u7528\u5b50\u67e5\u8be2\u8ba1\u7b97\u6bcf\u4e2a\u5206\u7ec4\uff08user_id\u3001product_id\uff09\u7684 create_time\u6700\u5927\u503c\u3002\u63a5\u7740\uff0c\u5c06\u8be5\u5b50\u67e5\u8be2\u4e0e\u539f\u8868\u5173\u8054\uff0c\u6761\u4ef6\u4e3a user_id\u3001product_id \u76f8\u7b49\uff0c\u4e14 create_time \u4e3a\u6700\u5927\u503c\u3002 \u6539\u8fdb\u540e\u7684\uff1a select t2.id, t1.* from ( select max(create_time) as create_time, user_id, product_id from demo group by user_id, product_id ) t1 left join demo t2 on t1.user_id = t2.user_id and t1.product_id = t2.product_id and t1.create_time = t2.create_time \u767b\u5f55\u540e\u590d\u5236 \u89e3\u91ca\uff1a \u5b50\u67e5\u8be2 t1 \u8ba1\u7b97\u6bcf\u4e2a\u5206\u7ec4\u7684 create_time \u6700\u5927\u503c\u3002 [&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-7265","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7265","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=7265"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7265\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}