{"id":25812,"date":"2024-11-24T14:22:35","date_gmt":"2024-11-24T06:22:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25812\/"},"modified":"2024-11-24T14:22:35","modified_gmt":"2024-11-24T06:22:35","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mysql-%e5%88%86%e7%bb%84%e6%9f%a5%e8%af%a2%e6%80%a7%e5%88%ab%e5%90%88%e8%ae%a1%e5%8f%8a%e5%a7%93%e5%90%8d%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25812\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 MySQL \u5206\u7ec4\u67e5\u8be2\u6027\u522b\u5408\u8ba1\u53ca\u59d3\u540d\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173070885613913.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 MySQL \u5206\u7ec4\u67e5\u8be2\u6027\u522b\u5408\u8ba1\u53ca\u59d3\u540d\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 MySQL \u5206\u7ec4\u67e5\u8be2\u6027\u522b\u5408\u8ba1\u53ca\u59d3\u540d\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u901a\u8fc7  \u5206\u7ec4\u67e5\u8be2\u6027\u522b\u5408\u8ba1\u53ca\u59d3\u540d<\/p>\n<p>\u4e00\u4e2a\u73ed\u7ea7\u62e5\u6709 50 \u540d\u5b66\u751f\uff0c\u6027\u522b\u6570\u636e\u5df2\u5b58\u5728\u3002\u73b0\u5728\u9700\u8981\u6839\u636e\u6027\u522b\u5bf9\u5b66\u751f\u59d3\u540d\u8fdb\u884c\u5206\u7ec4\uff0c\u5f97\u5230\u4e24\u7ec4\u6570\u636e\uff0c\u6bcf\u7ec4\u5305\u542b\u76f8\u540c\u6027\u522b\u7684\u6240\u6709\u59d3\u540d\u3002<\/p>\n<p>\u6b63\u786e\u7684 mysql \u67e5\u8be2\u8bed\u53e5\u4e3a\uff1a<\/p>\n<pre>create table students (\n    name varchar(100),\n    gender varchar(10)\n);\ninsert into students values('\u5c0f\u660e', '\u7537'), ('\u5c0f\u674e', '\u7537'), ('\u5c0f\u7ea2', '\u5973'), ('\u5c0f\u7eff', '\u5973');\nselect gender, count(1), group_concat(name) from `students` group by gender;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7ed3\u679c\u5982\u4e0b\u8868\u6240\u793a\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>gender<\/th>\n<th>sum<\/th>\n<th>name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u5973<\/td>\n<td>2<\/td>\n<td>\u5c0f\u7ea2,\u5c0f\u7eff<\/td>\n<\/tr>\n<tr>\n<td>\u7537<\/td>\n<td>2<\/td>\n<td>\u5c0f\u660e,\u5c0f\u674e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u901a\u8fc7 group_concat \u51fd\u6570\uff0c\u53ef\u4ee5\u5c06\u76f8\u540c\u6027\u522b\u5b66\u751f\u7684\u59d3\u540d\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4ece\u800c\u8fbe\u5230\u6309\u6027\u522b\u5206\u7ec4\u7684\u9700\u6c42\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL \u5206\u7ec4\u67e5\u8be2\u6027\u522b\u5408\u8ba1\u53ca\u59d3\u540d\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>\u5982\u4f55\u901a\u8fc7 \u5206\u7ec4\u67e5\u8be2\u6027\u522b\u5408\u8ba1\u53ca\u59d3\u540d \u4e00\u4e2a\u73ed\u7ea7\u62e5\u6709 50 \u540d\u5b66\u751f\uff0c\u6027\u522b\u6570\u636e\u5df2\u5b58\u5728\u3002\u73b0\u5728\u9700\u8981\u6839\u636e\u6027\u522b\u5bf9\u5b66\u751f\u59d3\u540d\u8fdb\u884c\u5206\u7ec4\uff0c\u5f97\u5230\u4e24\u7ec4\u6570\u636e\uff0c\u6bcf\u7ec4\u5305\u542b\u76f8\u540c\u6027\u522b\u7684\u6240\u6709\u59d3\u540d\u3002 \u6b63\u786e\u7684 mysql \u67e5\u8be2\u8bed\u53e5\u4e3a\uff1a create table students ( name varchar(100), gender varchar(10) ); insert into students values(&#8216;\u5c0f\u660e&#8217;, &#8216;\u7537&#8217;), (&#8216;\u5c0f\u674e&#8217;, &#8216;\u7537&#8217;), (&#8216;\u5c0f\u7ea2&#8217;, &#8216;\u5973&#8217;), (&#8216;\u5c0f\u7eff&#8217;, &#8216;\u5973&#8217;); select gender, count(1), group_concat(name) from `students` group by gender; \u767b\u5f55\u540e\u590d\u5236 \u7ed3\u679c\u5982\u4e0b\u8868\u6240\u793a\uff1a gender sum name \u5973 2 \u5c0f\u7ea2,\u5c0f\u7eff \u7537 2 \u5c0f\u660e,\u5c0f\u674e \u901a\u8fc7 group_concat \u51fd\u6570\uff0c\u53ef\u4ee5\u5c06\u76f8\u540c\u6027\u522b\u5b66\u751f\u7684\u59d3\u540d\u5408\u5e76\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4ece\u800c\u8fbe\u5230\u6309\u6027\u522b\u5206\u7ec4\u7684\u9700\u6c42\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL \u5206\u7ec4\u67e5\u8be2\u6027\u522b\u5408\u8ba1\u53ca\u59d3\u540d\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-25812","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25812","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=25812"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25812\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}