{"id":25677,"date":"2024-11-24T14:00:35","date_gmt":"2024-11-24T06:00:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25677\/"},"modified":"2024-11-24T14:00:35","modified_gmt":"2024-11-24T06:00:35","slug":"mysql-5-7-%e5%ad%90%e6%9f%a5%e8%af%a2%e6%8e%92%e5%ba%8f%e5%a4%b1%e6%95%88%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25677\/","title":{"rendered":"MySQL 5.7 \u5b50\u67e5\u8be2\u6392\u5e8f\u5931\u6548\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173068075544880.jpg\" class=\"aligncenter\" title=\"MySQL 5.7 \u5b50\u67e5\u8be2\u6392\u5e8f\u5931\u6548\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"MySQL 5.7 \u5b50\u67e5\u8be2\u6392\u5e8f\u5931\u6548\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4e2d\u5b50\u67e5\u8be2\u6392\u5e8f\u5931\u6548\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728mysql\u7248\u672c5.7.13\u4e2d\uff0c\u6709\u4e00\u79cd\u5e38\u89c1\u95ee\u9898\u662f\u5b50\u67e5\u8be2\u4e2d\u7684\u6392\u5e8f\u4e0d\u4f1a\u88ab\u4fdd\u7559\u3002\u8fd9\u7ed9\u5f00\u53d1\u4eba\u5458\u5e26\u6765\u4e86\u56f0\u6270\uff0c\u56e0\u4e3a\u4ed6\u4eec\u9700\u8981\u5728\u5b50\u67e5\u8be2\u4e2d\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u5c06\u7ed3\u679c\u7528\u4e8e\u5916\u90e8\u67e5\u8be2\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528\u7a97\u53e3\u51fd\u6570<\/strong><\/p>\n<p>\u5bf9\u4e8e\u7248\u672c5.8\u4ee5\u4e0a\u7684mysql\uff0c\u53ef\u4ee5\u4f7f\u7528\u7a97\u53e3\u51fd\u6570\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002\u7a97\u53e3\u51fd\u6570\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5728\u6570\u636e\u5206\u7ec4\u540e\u5bf9\u5176\u8fdb\u884c\u6392\u5e8f\uff0c\u4ece\u800c\u4fdd\u7559\u6392\u5e8f\u7ed3\u679c\u3002\u7136\u800c\uff0c5.7\u7248\u672c\u4e0d\u652f\u6301\u7a97\u53e3\u51fd\u6570\u3002<\/p>\n<p><strong>\u65b9\u6cd5\u4e8c\uff1a\u9884\u5148\u8ba1\u7b97\u5e76\u5173\u8054<\/strong><\/p>\n<p>\u5bf9\u4e8e5.7\u7248\u672cmysql\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u5148\u6309\u5206\u7ec4\u5b57\u6bb5\u8ba1\u7b97\u6bcf\u4e2a\u5206\u7ec4\u7684\u6700\u5927create_time\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u4e00\u4e2a\u4e2d\u95f4\u8868\u4e2d\u3002<\/li>\n<li>\u5c06\u4e2d\u95f4\u8868\u4e0e\u539f\u59cb\u8868\u5173\u8054\uff0c\u68c0\u7d22\u5177\u6709\u6700\u5927create_time\u7684\u8bb0\u5f55\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0bsql\u4ee3\u7801\u5c55\u793a\u4e86\u8be5\u65b9\u6cd5\uff1a<\/p>\n<pre>select t2.id, t1.* from (\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>\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u51c6\u786e\u5730\u83b7\u53d6\u540c\u4e00\u4e2a\u7528\u6237\u540c\u4e00\u4ea7\u54c1\u7684\u6700\u65b0\u8bb0\u5f55\uff0c\u800c\u4e0d\u4f1a\u53d7\u5b50\u67e5\u8be2\u6392\u5e8f\u5931\u6548\u7684\u5f71\u54cd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL 5.7 \u5b50\u67e5\u8be2\u6392\u5e8f\u5931\u6548\u5982\u4f55\u89e3\u51b3\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>\u4e2d\u5b50\u67e5\u8be2\u6392\u5e8f\u5931\u6548\u7684\u89e3\u51b3\u65b9\u6cd5 \u5728mysql\u7248\u672c5.7.13\u4e2d\uff0c\u6709\u4e00\u79cd\u5e38\u89c1\u95ee\u9898\u662f\u5b50\u67e5\u8be2\u4e2d\u7684\u6392\u5e8f\u4e0d\u4f1a\u88ab\u4fdd\u7559\u3002\u8fd9\u7ed9\u5f00\u53d1\u4eba\u5458\u5e26\u6765\u4e86\u56f0\u6270\uff0c\u56e0\u4e3a\u4ed6\u4eec\u9700\u8981\u5728\u5b50\u67e5\u8be2\u4e2d\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u5c06\u7ed3\u679c\u7528\u4e8e\u5916\u90e8\u67e5\u8be2\u3002 \u4e3a\u4e86\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a \u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528\u7a97\u53e3\u51fd\u6570 \u5bf9\u4e8e\u7248\u672c5.8\u4ee5\u4e0a\u7684mysql\uff0c\u53ef\u4ee5\u4f7f\u7528\u7a97\u53e3\u51fd\u6570\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002\u7a97\u53e3\u51fd\u6570\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5728\u6570\u636e\u5206\u7ec4\u540e\u5bf9\u5176\u8fdb\u884c\u6392\u5e8f\uff0c\u4ece\u800c\u4fdd\u7559\u6392\u5e8f\u7ed3\u679c\u3002\u7136\u800c\uff0c5.7\u7248\u672c\u4e0d\u652f\u6301\u7a97\u53e3\u51fd\u6570\u3002 \u65b9\u6cd5\u4e8c\uff1a\u9884\u5148\u8ba1\u7b97\u5e76\u5173\u8054 \u5bf9\u4e8e5.7\u7248\u672cmysql\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u5148\u6309\u5206\u7ec4\u5b57\u6bb5\u8ba1\u7b97\u6bcf\u4e2a\u5206\u7ec4\u7684\u6700\u5927create_time\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u4e00\u4e2a\u4e2d\u95f4\u8868\u4e2d\u3002 \u5c06\u4e2d\u95f4\u8868\u4e0e\u539f\u59cb\u8868\u5173\u8054\uff0c\u68c0\u7d22\u5177\u6709\u6700\u5927create_time\u7684\u8bb0\u5f55\u3002 \u4ee5\u4e0bsql\u4ee3\u7801\u5c55\u793a\u4e86\u8be5\u65b9\u6cd5\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 \u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u51c6\u786e\u5730\u83b7\u53d6\u540c\u4e00\u4e2a\u7528\u6237\u540c\u4e00\u4ea7\u54c1\u7684\u6700\u65b0\u8bb0\u5f55\uff0c\u800c\u4e0d\u4f1a\u53d7\u5b50\u67e5\u8be2\u6392\u5e8f\u5931\u6548\u7684\u5f71\u54cd\u3002 \u4ee5\u4e0a\u5c31\u662fMySQL 5.7 \u5b50\u67e5\u8be2\u6392\u5e8f\u5931\u6548\u5982\u4f55\u89e3\u51b3\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-25677","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25677","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=25677"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25677\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}