{"id":200598,"date":"2025-05-06T09:06:51","date_gmt":"2025-05-06T01:06:51","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200598\/"},"modified":"2025-05-06T09:06:51","modified_gmt":"2025-05-06T01:06:51","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:\/\/server.hk\/cnblog\/200598\/","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><b><\/b> <\/p>\n<h1>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<\/h1>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241109\/1731134373672f03a546b41.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>mysql\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\u7684sql\u8bed\u53e5\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><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>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aMySQL 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\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>MySQL 5.7 \u5b50\u67e5\u8be2\u6392\u5e8f\uff1a&#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-200598","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200598","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=200598"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200598\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}