{"id":5993,"date":"2024-11-14T08:19:52","date_gmt":"2024-11-14T00:19:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5993\/"},"modified":"2024-11-14T08:19:52","modified_gmt":"2024-11-14T00:19:52","slug":"sql%e4%b8%ad%e6%98%af%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5993\/","title":{"rendered":"sql\u4e2d:\u662f\u4ec0\u4e48\u610f\u601d"},"content":{"rendered":"<p><strong>sql \u4e2d count(*) \u7684\u542b\u4e49<\/strong><\/p>\n<p>\u5728 SQL \u4e2d\uff0cCOUNT(*) \u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u8868\u4e2d\u8bb0\u5f55\u7684\u6570\u91cf\u3002\u5b83\u662f\u4e00\u4e2a\uff0c\u53ef\u4ee5\u5e94\u7528\u4e8e\u4efb\u4f55\u8868\u6216\u67e5\u8be2\uff0c\u65e0\u8bba\u5176\u7ed3\u6784\u6216\u5185\u5bb9\u5982\u4f55\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong> COUNT(*) \u4e0e COUNT(column) \u4e0d\u540c\uff0c\u540e\u8005\u53ea\u8ba1\u7b97\u6307\u5b9a\u5217\u7684\u975e\u7a7a\u503c\u7684\u6570\u91cf\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<pre>COUNT(*)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ed3\u679c<\/strong><\/p>\n<p>\u8be5\u51fd\u6570\u8fd4\u56de\u8868\u4e2d\u8bb0\u5f55\u7684\u603b\u6570\uff0c\u5305\u62ec\u7a7a\u503c\u548c\u91cd\u590d\u503c\u3002<\/p>\n<p><strong>\u7528\u9014<\/strong><\/p>\n<p>COUNT(*) \u51fd\u6570\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u975e\u5e38\u6709\u7528\uff1a<\/p>\n<ul>\n<li>\u67e5\u627e\u8868\u4e2d\u8bb0\u5f55\u7684\u6570\u91cf<\/li>\n<li>\u8ba1\u7b97\u8868\u4e2d\u8bb0\u5f55\u7684\u5b50\u96c6<\/li>\n<li>\u4f5c\u4e3a\u805a\u5408\u51fd\u6570\u5728\u5206\u7ec4\u64cd\u4f5c\u4e2d\u4f7f\u7528<\/li>\n<li>\u5728\u5b50\u67e5\u8be2\u4e2d\u4f7f\u7528\uff0c\u4ee5\u9650\u5236\u8fd4\u56de\u7684\u7ed3\u679c\u6570\u91cf<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<pre>SELECT COUNT(*)\nFROM customers;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u67e5\u8be2\u5c06\u8fd4\u56de customers \u8868\u4e2d\u8bb0\u5f55\u7684\u603b\u6570\u3002<\/p>\n<pre>SELECT COUNT(*)\nFROM orders\nWHERE order_date &gt; '2023-01-01';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u67e5\u8be2\u5c06\u8fd4\u56de orders \u8868\u4e2d\u65e5\u671f\u5927\u4e8e 2023-01-01 \u7684\u8bb0\u5f55\u7684\u6570\u91cf\u3002<\/p>\n<pre>SELECT department_id, COUNT(*)\nFROM employees\nGROUP BY department_id;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u67e5\u8be2\u5c06\u8fd4\u56de\u4e00\u4e2a\u7ed3\u679c\u96c6\uff0c\u5176\u4e2d\u663e\u793a\u6bcf\u4e2a\u90e8\u95e8\u4e2d\u5458\u5de5\u7684\u6570\u91cf\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u4e2d:\u662f\u4ec0\u4e48\u610f\u601d\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>sql \u4e2d count(*) \u7684\u542b\u4e49 \u5728 SQL \u4e2d\uff0cCOUNT(*) \u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u8868\u4e2d\u8bb0\u5f55\u7684\u6570\u91cf\u3002\u5b83\u662f\u4e00\u4e2a\uff0c\u53ef\u4ee5\u5e94\u7528\u4e8e\u4efb\u4f55\u8868\u6216\u67e5\u8be2\uff0c\u65e0\u8bba\u5176\u7ed3\u6784\u6216\u5185\u5bb9\u5982\u4f55\u3002 \u6ce8\u610f\uff1a COUNT(*) \u4e0e COUNT(column) \u4e0d\u540c\uff0c\u540e\u8005\u53ea\u8ba1\u7b97\u6307\u5b9a\u5217\u7684\u975e\u7a7a\u503c\u7684\u6570\u91cf\u3002 \u8bed\u6cd5 COUNT(*) \u767b\u5f55\u540e\u590d\u5236 \u7ed3\u679c \u8be5\u51fd\u6570\u8fd4\u56de\u8868\u4e2d\u8bb0\u5f55\u7684\u603b\u6570\uff0c\u5305\u62ec\u7a7a\u503c\u548c\u91cd\u590d\u503c\u3002 \u7528\u9014 COUNT(*) \u51fd\u6570\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u975e\u5e38\u6709\u7528\uff1a \u67e5\u627e\u8868\u4e2d\u8bb0\u5f55\u7684\u6570\u91cf \u8ba1\u7b97\u8868\u4e2d\u8bb0\u5f55\u7684\u5b50\u96c6 \u4f5c\u4e3a\u805a\u5408\u51fd\u6570\u5728\u5206\u7ec4\u64cd\u4f5c\u4e2d\u4f7f\u7528 \u5728\u5b50\u67e5\u8be2\u4e2d\u4f7f\u7528\uff0c\u4ee5\u9650\u5236\u8fd4\u56de\u7684\u7ed3\u679c\u6570\u91cf \u793a\u4f8b SELECT COUNT(*) FROM customers; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u67e5\u8be2\u5c06\u8fd4\u56de customers \u8868\u4e2d\u8bb0\u5f55\u7684\u603b\u6570\u3002 SELECT COUNT(*) FROM orders WHERE order_date &gt; &#8216;2023-01-01&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u67e5\u8be2\u5c06\u8fd4\u56de orders \u8868\u4e2d\u65e5\u671f\u5927\u4e8e 2023-01-01 \u7684\u8bb0\u5f55\u7684\u6570\u91cf\u3002 SELECT department_id, COUNT(*) FROM employees GROUP BY [&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-5993","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5993","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=5993"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5993\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}