{"id":7089,"date":"2024-11-14T09:19:00","date_gmt":"2024-11-14T01:19:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7089\/"},"modified":"2024-11-14T09:19:00","modified_gmt":"2024-11-14T01:19:00","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mysql-group-by-%e8%af%ad%e5%8f%a5%e5%af%b9%e5%b8%83%e5%b0%94%e5%ad%97%e6%ae%b5%e8%bf%9b%e8%a1%8c%e8%81%9a%e5%90%88%ef%bc%8c%e7%bb%9f%e8%ae%a1-null%e3%80%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7089\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 MySQL group by \u8bed\u53e5\u5bf9\u5e03\u5c14\u5b57\u6bb5\u8fdb\u884c\u805a\u5408\uff0c\u7edf\u8ba1 NULL\u3001\u7a7a\u5b57\u7b26\u4e32\u548c\u6709\u5b9e\u9645\u503c\u7684\u8bb0\u5f55\u6570\u91cf\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173043238798169.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 MySQL group by \u8bed\u53e5\u5bf9\u5e03\u5c14\u5b57\u6bb5\u8fdb\u884c\u805a\u5408\uff0c\u7edf\u8ba1 NULL\u3001\u7a7a\u5b57\u7b26\u4e32\u548c\u6709\u5b9e\u9645\u503c\u7684\u8bb0\u5f55\u6570\u91cf\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 MySQL group by \u8bed\u53e5\u5bf9\u5e03\u5c14\u5b57\u6bb5\u8fdb\u884c\u805a\u5408\uff0c\u7edf\u8ba1 NULL\u3001\u7a7a\u5b57\u7b26\u4e32\u548c\u6709\u5b9e\u9645\u503c\u7684\u8bb0\u5f55\u6570\u91cf\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4f7f\u7528 group by\u5224\u65ad\u5e03\u5c14\u503c<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5982\u4f55\u4f7f\u7528mysql group by\u8bed\u53e5\u5bf9\u5e03\u5c14\u5b57\u6bb5\u8fdb\u884c\u805a\u5408\uff0c\u5e76\u5206\u522b\u7edf\u8ba1\u4e3anull\u3001&#8221;\uff08\u7a7a\u5b57\u7b26\uff09\u548c\u6709\u5b9e\u9645\u503c\u7684\u8bb0\u5f55\u6570\u91cf\uff1f<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<pre>select \n    d.checks, count(d.checks)\nfrom (select (\n    case clip_url_hash\n    when '' then '\u7a7a\u5b57\u7b26\u4e32'\n    when null then 'NULL'\n    else '\u6b63\u5e38\u7684' end\n) as checks from text_meta_ingest) as d\ngroup by d.checks;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5206\u6790\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528case when\u8bed\u53e5\u5bf9clip_url_hash\u5b57\u6bb5\u8fdb\u884c\u5224\u65ad\uff1a<\/p>\n<ul>\n<li>\u4e3a\u7a7a\u5b57\u7b26\u4e32\u65f6\uff0c\u8fd4\u56de\u201c\u7a7a\u5b57\u7b26\u4e32\u201d<\/li>\n<li>\u4e3anull\u65f6\uff0c\u8fd4\u56de\u201cnull\u201d<\/li>\n<li>\u5426\u5219\uff0c\u8fd4\u56de\u201c\u6b63\u5e38\u7684\u201d<\/li>\n<\/ul>\n<\/li>\n<li>\u5c06case when\u7684\u5224\u65ad\u7ed3\u679c\u7528as checks\u8d77\u522b\u540d\uff0c\u5e76\u4f5c\u4e3a\u65b0\u7684\u6570\u636e\u96c6d.checks<\/li>\n<li>\u5bf9d.checks\u6570\u636e\u96c6\u8fdb\u884cgroup by\u805a\u5408\uff0c\u5e76\u7edf\u8ba1\u5404\u7ec4\u7684\u8bb0\u5f55\u6570\u91cf<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL group by \u8bed\u53e5\u5bf9\u5e03\u5c14\u5b57\u6bb5\u8fdb\u884c\u805a\u5408\uff0c\u7edf\u8ba1 NULL\u3001\u7a7a\u5b57\u7b26\u4e32\u548c\u6709\u5b9e\u9645\u503c\u7684\u8bb0\u5f55\u6570\u91cf\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>\u4f7f\u7528 group by\u5224\u65ad\u5e03\u5c14\u503c \u95ee\u9898\uff1a \u5982\u4f55\u4f7f\u7528mysql group by\u8bed\u53e5\u5bf9\u5e03\u5c14\u5b57\u6bb5\u8fdb\u884c\u805a\u5408\uff0c\u5e76\u5206\u522b\u7edf\u8ba1\u4e3anull\u3001&#8221;\uff08\u7a7a\u5b57\u7b26\uff09\u548c\u6709\u5b9e\u9645\u503c\u7684\u8bb0\u5f55\u6570\u91cf\uff1f \u89e3\u51b3\u65b9\u6848\uff1a select d.checks, count(d.checks) from (select ( case clip_url_hash when &#8221; then &#8216;\u7a7a\u5b57\u7b26\u4e32&#8217; when 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 \u5206\u6790\uff1a \u4f7f\u7528case when\u8bed\u53e5\u5bf9clip_url_hash\u5b57\u6bb5\u8fdb\u884c\u5224\u65ad\uff1a \u4e3a\u7a7a\u5b57\u7b26\u4e32\u65f6\uff0c\u8fd4\u56de\u201c\u7a7a\u5b57\u7b26\u4e32\u201d \u4e3anull\u65f6\uff0c\u8fd4\u56de\u201cnull\u201d \u5426\u5219\uff0c\u8fd4\u56de\u201c\u6b63\u5e38\u7684\u201d \u5c06case when\u7684\u5224\u65ad\u7ed3\u679c\u7528as checks\u8d77\u522b\u540d\uff0c\u5e76\u4f5c\u4e3a\u65b0\u7684\u6570\u636e\u96c6d.checks \u5bf9d.checks\u6570\u636e\u96c6\u8fdb\u884cgroup by\u805a\u5408\uff0c\u5e76\u7edf\u8ba1\u5404\u7ec4\u7684\u8bb0\u5f55\u6570\u91cf \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL group by \u8bed\u53e5\u5bf9\u5e03\u5c14\u5b57\u6bb5\u8fdb\u884c\u805a\u5408\uff0c\u7edf\u8ba1 NULL\u3001\u7a7a\u5b57\u7b26\u4e32\u548c\u6709\u5b9e\u9645\u503c\u7684\u8bb0\u5f55\u6570\u91cf\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7089","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7089","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=7089"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7089\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}