{"id":7106,"date":"2024-11-14T10:01:36","date_gmt":"2024-11-14T02:01:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7106\/"},"modified":"2024-11-14T10:01:36","modified_gmt":"2024-11-14T02:01:36","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-group-by-%e5%90%8e%e5%af%b9-mysql-%e7%bb%93%e6%9e%9c%e8%bf%9b%e8%a1%8c%e6%9d%a1%e4%bb%b6%e5%88%a4%e6%96%ad%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7106\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 GROUP BY \u540e\u5bf9 MySQL \u7ed3\u679c\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173044669096369.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 GROUP BY \u540e\u5bf9 MySQL \u7ed3\u679c\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 GROUP BY \u540e\u5bf9 MySQL \u7ed3\u679c\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728\u4f7f\u7528 group by \u540e\u5bf9  \u7ed3\u679c\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\uff1f<\/strong><\/p>\n<p>\u5728 mysql \u4e2d\u4f7f\u7528 group by \u5bf9\u7ed3\u679c\u5206\u7ec4\u65f6\uff0c\u6211\u4eec\u6709\u65f6\u9700\u8981\u8fdb\u4e00\u6b65\u5bf9\u5206\u7ec4\u540e\u7684\u6570\u636e\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u9700\u8981\u7edf\u8ba1\u5217 clip_url_hash \u7684\u4e09\u79cd\u60c5\u51b5\uff1anull\u3001&#8221;\uff08\u7a7a\u5b57\u7b26\u4e32\uff09\u548c\u6709\u5b9e\u9645\u503c\u3002<\/p>\n<p>\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e2a\u76ee\u6807\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528 case when \u8bed\u53e5\u3002<\/p>\n<pre>select\n    d.checks,\n    count(d.checks)\nfrom (\n    select\n    case\n        when clip_url_hash = '' then '\u7a7a\u5b57\u7b26\u4e32'\n        when clip_url_hash is null then 'null'\n        else '\u6b63\u5e38\u7684'\n    end as checks\n    from text_meta_ingest\n) as d\ngroup by\n    d.checks;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n<ul>\n<li>\u5185\u5c42\u67e5\u8be2\u4f7f\u7528 case when \u8bed\u53e5\u5c06 clip_url_hash \u503c\u6620\u5c04\u4e3a\u4e09\u4e2a\u4e0d\u540c\u7684\u68c0\u67e5\u7ed3\u679c\uff1a\u7a7a\u5b57\u7b26\u4e32\u3001null \u548c\u6b63\u5e38\u503c\u3002<\/li>\n<li>\u5916\u5c42\u67e5\u8be2\u4f7f\u7528 count() \u51fd\u6570\u5bf9 checks \u5217\u8fdb\u884c\u8ba1\u6570\u3002<\/li>\n<li>group by \u5b50\u53e5\u6839\u636e checks \u503c\u5bf9\u7ed3\u679c\u8fdb\u884c\u5206\u7ec4\u3002<\/li>\n<\/ul>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>checks    count\n\u7a7a\u5b57\u7b26\u4e32    xxx\nNULL    yyy\n\u6b63\u5e38\u7684    zzz<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 GROUP BY \u540e\u5bf9 MySQL \u7ed3\u679c\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728\u4f7f\u7528 group by \u540e\u5bf9 \u7ed3\u679c\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\uff1f \u5728 mysql \u4e2d\u4f7f\u7528 group by \u5bf9\u7ed3\u679c\u5206\u7ec4\u65f6\uff0c\u6211\u4eec\u6709\u65f6\u9700\u8981\u8fdb\u4e00\u6b65\u5bf9\u5206\u7ec4\u540e\u7684\u6570\u636e\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u9700\u8981\u7edf\u8ba1\u5217 clip_url_hash \u7684\u4e09\u79cd\u60c5\u51b5\uff1anull\u3001&#8221;\uff08\u7a7a\u5b57\u7b26\u4e32\uff09\u548c\u6709\u5b9e\u9645\u503c\u3002 \u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e2a\u76ee\u6807\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528 case when \u8bed\u53e5\u3002 select d.checks, count(d.checks) from ( select case when clip_url_hash = &#8221; then &#8216;\u7a7a\u5b57\u7b26\u4e32&#8217; when clip_url_hash is null then &#8216;null&#8217; else &#8216;\u6b63\u5e38\u7684&#8217; end as checks from text_meta_ingest ) as d group by d.checks; \u767b\u5f55\u540e\u590d\u5236 \u89e3\u91ca\uff1a \u5185\u5c42\u67e5\u8be2\u4f7f\u7528 case when \u8bed\u53e5\u5c06 [&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-7106","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7106","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=7106"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7106\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}