{"id":25814,"date":"2024-11-24T10:52:59","date_gmt":"2024-11-24T02:52:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25814\/"},"modified":"2024-11-24T10:52:59","modified_gmt":"2024-11-24T02:52:59","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8sql%e8%af%ad%e5%8f%a5%e5%b0%86%e5%ad%a6%e7%94%9f%e5%a7%93%e5%90%8d%e6%8c%89%e6%80%a7%e5%88%ab%e5%88%86%e7%bb%84%e5%b9%b6%e5%90%88%e5%b9%b6%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25814\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528SQL\u8bed\u53e5\u5c06\u5b66\u751f\u59d3\u540d\u6309\u6027\u522b\u5206\u7ec4\u5e76\u5408\u5e76\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173070974092392.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528SQL\u8bed\u53e5\u5c06\u5b66\u751f\u59d3\u540d\u6309\u6027\u522b\u5206\u7ec4\u5e76\u5408\u5e76\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528SQL\u8bed\u53e5\u5c06\u5b66\u751f\u59d3\u540d\u6309\u6027\u522b\u5206\u7ec4\u5e76\u5408\u5e76\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6309\u6027\u522b\u5206\u7ec4\u5e76\u5408\u5e76\u59d3\u540d<\/strong><\/p>\n<p>\u95ee\u9898\uff1a\u4e00\u4e2a\u73ed\u670950\u540d\u5b66\u751f\u7684\u4fe1\u606f\uff0c\u59d3\u540d\u548c\u6027\u522b\u5df2\u77e5\u3002\u9700\u8981\u6309\u6027\u522b\u5c06\u5b66\u751f\u5206\u7ec4\uff0c\u5e76\u628a\u6bcf\u7ec4\u7684\u59d3\u540d\u5408\u5e76\u3002<\/p>\n<p>\u7b54\u6848\uff1a\u4f7f\u7528 group_concat \u51fd\u6570\u53ef\u4ee5\u5b9e\u73b0\u9700\u6c42\u3002<\/p>\n<pre>select gender, count(1), group_concat(name)\nfrom students\ngroup by gender;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre>-- \u521b\u5efa\u8868\nCREATE TABLE students (\n    name VARCHAR(100),\n    gender VARCHAR(10)\n);\n\n-- \u63d2\u5165\u6570\u636e\nINSERT INTO students VALUES('\u5c0f\u660e', '\u7537'), ('\u5c0f\u674e', '\u7537'), ('\u5c0f\u7ea2', '\u5973'), ('\u5c0f\u7eff', '\u5973');\n\n-- \u6309\u6027\u522b\u5206\u7ec4\u5e76\u5408\u5e76\u59d3\u540d\nSELECT gender, count(1), group_concat(name)\nFROM students\nGROUP BY gender;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u793a\u4f8b\u7ed3\u679c\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>gender<\/th>\n<th>count<\/th>\n<th>name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u7537<\/td>\n<td>2<\/td>\n<td>\u5c0f\u660e,\u5c0f\u674e<\/td>\n<\/tr>\n<tr>\n<td>\u5973<\/td>\n<td>2<\/td>\n<td>\u5c0f\u7ea2,\u5c0f\u7eff<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528SQL\u8bed\u53e5\u5c06\u5b66\u751f\u59d3\u540d\u6309\u6027\u522b\u5206\u7ec4\u5e76\u5408\u5e76\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>\u6309\u6027\u522b\u5206\u7ec4\u5e76\u5408\u5e76\u59d3\u540d \u95ee\u9898\uff1a\u4e00\u4e2a\u73ed\u670950\u540d\u5b66\u751f\u7684\u4fe1\u606f\uff0c\u59d3\u540d\u548c\u6027\u522b\u5df2\u77e5\u3002\u9700\u8981\u6309\u6027\u522b\u5c06\u5b66\u751f\u5206\u7ec4\uff0c\u5e76\u628a\u6bcf\u7ec4\u7684\u59d3\u540d\u5408\u5e76\u3002 \u7b54\u6848\uff1a\u4f7f\u7528 group_concat \u51fd\u6570\u53ef\u4ee5\u5b9e\u73b0\u9700\u6c42\u3002 select gender, count(1), group_concat(name) from students group by gender; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a &#8212; \u521b\u5efa\u8868 CREATE TABLE students ( name VARCHAR(100), gender VARCHAR(10) ); &#8212; \u63d2\u5165\u6570\u636e 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;); &#8212; \u6309\u6027\u522b\u5206\u7ec4\u5e76\u5408\u5e76\u59d3\u540d SELECT gender, count(1), group_concat(name) FROM students GROUP BY gender; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\u7ed3\u679c\uff1a gender count [&hellip;]<\/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-25814","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25814","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=25814"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25814\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}