{"id":554381,"date":"2022-02-09T19:09:58","date_gmt":"2022-02-09T11:09:58","guid":{"rendered":"http:\/\/4563.org\/?p=554381"},"modified":"2022-02-09T19:09:58","modified_gmt":"2022-02-09T11:09:58","slug":"%e4%b8%80%e4%b8%aa-mysql-%e6%9f%a5%e8%af%a2%e9%97%ae%e9%a2%98-3","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=554381","title":{"rendered":"\u4e00\u4e2a MySQL \u67e5\u8be2\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1> \u4e00\u4e2a MySQL \u67e5\u8be2\u95ee\u9898 <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Macv1994 <\/span>  <span><i><\/i> 23<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6709\u4e00\u5f20\u79c1\u4fe1\u8868\u8868\u7ed3\u6784\u5982\u4e0b\u56fe<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2022\/01\/20220115_61e32427ef960.png\" alt=\"\u4e00\u4e2a MySQL \u67e5\u8be2\u95ee\u9898\" \/><\/p>\n<p>\u6211\u60f3\u628a\u5f53\u524d\u7528\u6237\u7684\u6240\u6709\u79c1\u4fe1\u67e5\u8be2\u51fa\u6765\uff0c\u6211\u73b0\u5728\u4f7f\u7528\u7684\u4e0b\u9762\u7684\u67e5\u8be2\u8bed\u53e5<\/p>\n<pre><code># \u5047\u8bbe\u5f53\u524d\u7528\u6237 id \u4e3a 12 select * from t_message where receiver_id == 12 group by sender_id; <\/code><\/pre>\n<p>\u4f46\u662f\u8fd9\u6837\u6709\u4e24\u4e2a\u95ee\u9898<\/p>\n<ol>\n<li>\u5982\u679c\u662f 12 \u7528\u6237\u7ed9\u5176\u4ed6\u7528\u6237\u53d1\u9001\u7684\u79c1\u4fe1\uff0c\u5982\u679c\u5bf9\u65b9\u6ca1\u6709\u56de\u590d\u7684\u8bdd\uff0c\u90a3\u4e48\u5c31\u67e5\u8be2\u4e0d\u51fa\u6765\u3002<\/li>\n<li>MySQL5.7 \u4ee5\u540e\u9ed8\u8ba4\u5f00\u542f\u4e86<code>ONLY_FULL_GROUP_BY<\/code>\uff0c\u7528\u4e0a\u9762\u7684\u67e5\u8be2\u8bed\u53e5\u4f1a\u62a5\u9519\uff0c\u8981\u5173\u6389\u624d\u53ef\u4ee5\u3002<\/li>\n<\/ol>\n<p>\u8bf7\u6c42\u5404\u4f4d\u5927\u4f6c\uff0c\u600e\u4e48\u89e3\u51b3\u5c0f\u5f1f\u8fd9\u4e2a\u95ee\u9898\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>17<\/span>) <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"7121063\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : onhao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> mysql8 only_full_group_by \u7684\u89e3\u51b3\u529e\u6cd5 https:\/\/wuhao.pw\/archives\/179\/ <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121064\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : onhao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @Macv1994 &#8220;\u5982\u679c\u662f 12 \u7528\u6237\u7ed9\u5176\u4ed6\u7528\u6237\u53d1\u9001\u7684\u79c1\u4fe1\uff0c\u5982\u679c\u5bf9\u65b9\u6ca1\u6709\u56de\u590d\u7684\u8bdd&#8221; \u90a3\u4e48 sender_id \u662f 12 \uff1f <br \/>mysql \u597d\u50cf receiver_id = 12 \u8fd9\u6837 \u5c31\u884c\u5427 \u4e0d\u9700\u8981== <br \/>\u53ef\u80fd\u662f\u6211\u7406\u89e3\u7684\u95ee\u9898\uff0c \u8fd9\u6837\u4e0d\u77e5\u53ef\u5426 <br \/>select * from t_message where receiver_id = 12 or sender_id=12 group by sender_id; <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121065\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cdcdc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u5982\u679c\u53ea\u662f\u4e3a\u4e86\u53bb\u91cd\uff0c\u5c31\u7528 select xxx, DISTINCT sender_id WHERE receiver_id = 12 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121066\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Macv1994 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @onhao ONLY_FULL_GROUP_BY \u901a\u8fc7\u67e5\u770b\u6587\u6863\u53ef\u4ee5\u901a\u8fc7 ANY_VALUE \u6765\u89e3\u51b3\u3002 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121067\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : onhao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @Macv1994 \u786e\u5b9e\uff0c\u91c7\u7528 any_value() \u4f3c\u4e4e\u66f4\u52a0\u597d\u3002 <br \/>\u53ea\u662f\u4f60\u7684\u95ee\u9898\uff0c\u6700\u7ec8\u600e\u4e48\u89e3\u51b3\u7684\uff1f <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121068\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : qianProgrammer <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> select * from t_message where receiver_id = 12<br \/>UNION<br \/>select * from t_message where sender_id = 12 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121069\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mitsuizzz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u53d1\u9001\u4eba\u6216\u8005\u63a5\u6536\u4eba id \u4e3a 12 \u4e0d\u5c31\u90fd\u67e5\u51fa\u6765\u4e86\uff0c\u6211\u7406\u89e3\u4e00\u884c\u5bf9\u5e94\u4e00\u6761\u79c1\u4fe1\uff0c\u67e5\u51fa\u6240\u6709\u79c1\u4fe1\u4e3a\u4ec0\u4e48\u8fd8\u8981\u5206\u7ec4 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121070\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lybcyd <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u4e3a\u4ec0\u4e48\u9700\u8981 group by \uff0c\u4e00\u4e2a\u53d1\u9001\u4eba\u53ea\u663e\u793a\u4e00\u6761\u5417\uff1f\u80fd\u660e\u786e\u4e00\u4e0b\u89c4\u5219\u4e48 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121071\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Macv1994 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @mitsuizzz <br \/>@lybcyd \u6211\u6ca1\u6709\u8868\u8ff0\u6e05\u695a\uff0c\u56e0\u4e3a\u6211\u8981\u505a\u4e00\u4e2a\u7c7b\u4f3c\u5fae\u4fe1\u804a\u5929\u5de6\u4fa7\u4fa7\u8fb9\u680f\u7684\u6548\u679c \u4e0d\u77e5\u9053\u662f\u4e0d\u662f\u6211\u60f3\u590d\u6742\u4e86 https:\/\/2dogz.cn\/backend\/files\/5076image.png <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121072\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Macv1994 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @onhao \u6211\u6700\u540e\u5206\u5f00\u4e24\u4e2a SQL \u8fdb\u884c group by <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121073\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : DefineJ <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u6211\u4eca\u5929\u521a\u628a\u804a\u5929\u8bb0\u5f55\u548c\u5217\u8868\u62c6\u5206\u51fa\u6765\uff0c\u5217\u8868\u53ea\u8bb0\u5f55\u6700\u540e\u4e00\u6b21\u804a\u5929 <img decoding=\"async\" src=\"https:\/\/i.imgur.com\/XutJACB.png\" rel=\"noreferrer\" alt=\"\u4e00\u4e2a MySQL \u67e5\u8be2\u95ee\u9898\"> <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121074\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : DefineJ <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> https:\/\/blog.csdn.net\/weixin_42260789\/article\/details\/119328074 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121075\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lybcyd <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @Macv1994 \u90a3\u6309\u7167\u4e1a\u52a1\u903b\u8f91\u5e94\u8be5\u662f\u9700\u8981\u65f6\u95f4\u5012\u5e8f\u7684\uff0cgroup by \u6392\u5e8f\u6211\u8bb0\u5f97\u662f\u6ca1\u6709\u4fdd\u8bc1\u7684\uff0c\u67e5\u8be2\u975e group by \u548c\u975e\u805a\u5408\u5b57\u6bb5\u4e5f\u4e0d\u7b26\u5408 SQL \u6807\u51c6\u3002<br \/>\u5982\u679c\u7528\u7684 MySQL8 \u53ef\u4ee5\u7528\u5f00\u7a97\u51fd\u6570\uff0c\u5982\u679c\u662f 5.7 \u90a3\u5c31\u5b50\u67e5\u8be2\u6309\u7167\u5bf9\u8bdd\u53cc\u65b9\u6765\u5206\u7ec4\u67e5\u8be2\u6700\u65b0\u65f6\u95f4\u3002<br \/>\u56e0\u4e3a\u8fd9\u91cc\u662f\u5bf9\u8bdd\uff0c\u5e94\u8be5\u9700\u8981\u6309\u7167 receiver \u548c sender \u4e24\u4e2a\u5b57\u6bb5\u5206\u7ec4\u5427\u3002 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121076\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : MidGap <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @Macv1994 \u7528 zset \u7ef4\u62a4\u4e2a\u8054\u7cfb\u4eba\u5217\u8868\u4f3c\u4e4e\u53ef\u4ee5\uff0cscore \u662f\u6700\u540e\u4e00\u6b21\u6d88\u606f\u7684\u65f6\u95f4\uff0c\u6392\u5e8f\u4e5f\u7701\u4e86 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121077\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Macv1994 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @lybcyd \u55ef\u662f\u7684\uff0cgroup by \u53ef\u4ee5\u901a\u8fc7 any_value \u6765\u89e3\u51b3\uff0c\u6211\u73b0\u5728\u662f\u5206\u5f00\u67e5\u8be2\u7684\uff0c\u5148\u628a\u6839\u636e sender_id \u5206\u7ec4\u6761\u4ef6\u4e3a receiver_id=12 \uff0c\u7136\u540e\u5c06\u6761\u4ef6\u8bbe\u7f6e\u4e3a sender_id=12 and receiver_id not in [group by sender_id] <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121078\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Macv1994 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @DefineJ \u611f\u8c22\uff0c\u6211\u770b\u4e00\u4e0b\u3002 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7121079\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Macv1994 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @MidGap \u4f60\u662f\u8bf4\u7528 redis \u7684 zset \u5417\uff1f <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a MySQL \u67e5\u8be2\u95ee\u9898 \u8cc7\u6df1\u5927&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/554381"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=554381"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/554381\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=554381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=554381"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=554381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}