{"id":122,"date":"2025-05-12T16:02:19","date_gmt":"2025-05-12T08:02:19","guid":{"rendered":"https:\/\/lib.kimsor.top\/?p=122"},"modified":"2025-11-10T20:56:58","modified_gmt":"2025-11-10T12:56:58","slug":"mysql%e4%b8%adgroup_concat%e7%9a%84%e5%a4%9a%e7%94%a8%e9%80%94","status":"publish","type":"post","link":"https:\/\/lib.kimsor.top\/?p=122","title":{"rendered":"Mysql\u4e2dGroup by\u5206\u7ec4\u76f8\u5173\u7684\u591a\u7528\u9014"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p><strong>1\u3001\u4f7f\u7528group_concat\u53ef\u4f7f\u7528distinct\u8fdb\u884c\u53bb\u91cd<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>group_concat(distinct name)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>2\u3001\u4f7f\u7528group_concat\u53ef\u4f7f\u7528order by\u8fdb\u884c\u6392\u5e8f<\/strong><\/p>\n\n\n\n<p>group_concat(name order by age desc)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>3\u3001\u4f7f\u7528group_concat\u642d\u914dSEPARATOR\u53ef\u4ee5\u81ea\u5b9a\u4e49\u8fde\u63a5\u7b26<\/strong><\/p>\n\n\n\n<p>group_concat(name separator &#8216;\u3001&#8217;)<\/p>\n\n\n\n<p>\u4f8b\u7ed3\u679c\uff1a\u5c0f\u660e\u3001\u5c0f\u674e\u3001\u5c0f\u7ea2<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>4\u3001\u4f7f\u7528case when\u7ed3\u5408group by\u53ef\u5355\u72ec\u5bf9\u7279\u5b9a\u6570\u636e\u5f52\u4e3a\u4e00\u7ec4<\/strong><\/p>\n\n\n\n<p>\u4f8b\uff1a\u5c06\u5f20\u4e09\u548c\u674e\u56db\u5f52\u4e3a\u4e00\u7ec4\u7edf\u8ba1\u5e74\u9f84\u4e4b\u548c\uff0c\u5176\u4ed6\u7684\u4eba\u72ec\u81ea\u7edf\u8ba1\u5e74\u9f84<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select \n  (case when \n      name in ('\u5f20\u4e09','\u674e\u56db') then '\u5f20\u4e09\u674e\u56db' \n      else name end) nameGroup,\n  sum(age) age\nfrom xxx \ngroup by nameGroup<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u4f7f\u7528group_concat\u53ef\u4f7f\u7528distinct\u8fdb\u884c\u53bb\u91cd 2\u3001\u4f7f\u7528group_concat\u53ef\u4f7f\u7528orde [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,3],"tags":[],"class_list":["post-122","post","type-post","status-publish","format-standard","hentry","category-mysql","category-database"],"_links":{"self":[{"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/posts\/122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=122"}],"version-history":[{"count":5,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":387,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions\/387"}],"wp:attachment":[{"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lib.kimsor.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}