{"id":5465,"date":"2024-11-14T10:29:41","date_gmt":"2024-11-14T02:29:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5465\/"},"modified":"2024-11-14T10:29:41","modified_gmt":"2024-11-14T02:29:41","slug":"mysql%e5%b9%b3%e5%9d%87%e5%80%bc%e6%80%8e%e4%b9%88%e6%9d%a5%e7%9a%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5465\/","title":{"rendered":"mysql\u5e73\u5747\u503c\u600e\u4e48\u6765\u7684"},"content":{"rendered":"<blockquote><p>\n  mysql \u4e2d\u7684\u5e73\u5747\u503c\u662f\u6570\u5b57\u603b\u548c\u9664\u4ee5\u6570\u91cf\u3002\u53ef\u4ee5\u901a\u8fc7 avg() \u51fd\u6570\u8ba1\u7b97\uff0c\u8be5\u51fd\u6570\u4e0d\u5305\u542b null \u503c\uff0c\u5e76\u5ffd\u7565\u6240\u6709\u8d1f\u6570\u503c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052815212166815.jpg\" class=\"aligncenter\" title=\"mysql\u5e73\u5747\u503c\u600e\u4e48\u6765\u7684\u63d2\u56fe\" alt=\"mysql\u5e73\u5747\u503c\u600e\u4e48\u6765\u7684\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5e73\u5747\u503c\u7684\u8ba1\u7b97<\/strong><\/p>\n<p>MySQL \u4e2d\u7684\u5e73\u5747\u503c\u8868\u793a\u4e00\u7ec4\u6570\u5b57\u7684\u603b\u548c\u9664\u4ee5\u6570\u91cf\u3002\u5b83\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51fd\u6570\u8ba1\u7b97\uff1a<\/p>\n<ul>\n<li> <strong>AVG() \u51fd\u6570\uff1a<\/strong>\u8ba1\u7b97\u4e00\u7ec4\u6570\u5b57\u7684\u5e73\u5747\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u65b9\u5f0f\uff1a<\/strong><\/p>\n<p>AVG(expression)<\/p>\n<p>\u5176\u4e2d expression \u662f\u8981\u8ba1\u7b97\u5e73\u5747\u503c\u7684\u6570\u5b57\u5217\u6216\u8868\u8fbe\u5f0f\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u8ba1\u7b97\u8868\u4e2d sales \u5217\u7684\u5e73\u5747\u9500\u552e\u989d\uff1a<\/p>\n<pre>SELECT AVG(sales) FROM sales_table;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<p>\u5e73\u5747\u9500\u552e\u989d\uff0c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002<\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>AVG() \u51fd\u6570\u5ffd\u7565 NULL \u503c\u3002<\/li>\n<li>\u5982\u679c\u8ba1\u7b97\u4e2d\u6ca1\u6709\u6570\u5b57\u503c\uff08\u5373\u6240\u6709\u503c\u4e3a NULL\uff09\uff0c\u5219\u7ed3\u679c\u5c06\u4e3a NULL\u3002<\/li>\n<li>\u5bf9\u4e8e\u5305\u542b\u8d1f\u6570\u7684\u6570\u5b57\u96c6\uff0cAVG() \u4f1a\u8fd4\u56de\u8d1f\u6570\u5e73\u5747\u503c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5e73\u5747\u503c\u600e\u4e48\u6765\u7684\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>mysql \u4e2d\u7684\u5e73\u5747\u503c\u662f\u6570\u5b57\u603b\u548c\u9664\u4ee5\u6570\u91cf\u3002\u53ef\u4ee5\u901a\u8fc7 avg() \u51fd\u6570\u8ba1\u7b97\uff0c\u8be5\u51fd\u6570\u4e0d\u5305\u542b null \u503c\uff0c\u5e76\u5ffd\u7565\u6240\u6709\u8d1f\u6570\u503c\u3002 MySQL \u5e73\u5747\u503c\u7684\u8ba1\u7b97 MySQL \u4e2d\u7684\u5e73\u5747\u503c\u8868\u793a\u4e00\u7ec4\u6570\u5b57\u7684\u603b\u548c\u9664\u4ee5\u6570\u91cf\u3002\u5b83\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51fd\u6570\u8ba1\u7b97\uff1a AVG() \u51fd\u6570\uff1a\u8ba1\u7b97\u4e00\u7ec4\u6570\u5b57\u7684\u5e73\u5747\u503c\u3002 \u4f7f\u7528\u65b9\u5f0f\uff1a AVG(expression) \u5176\u4e2d expression \u662f\u8981\u8ba1\u7b97\u5e73\u5747\u503c\u7684\u6570\u5b57\u5217\u6216\u8868\u8fbe\u5f0f\u3002 \u793a\u4f8b\uff1a \u8ba1\u7b97\u8868\u4e2d sales \u5217\u7684\u5e73\u5747\u9500\u552e\u989d\uff1a SELECT AVG(sales) FROM sales_table; \u767b\u5f55\u540e\u590d\u5236 \u7ed3\u679c\uff1a \u5e73\u5747\u9500\u552e\u989d\uff0c\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002 \u6ce8\u610f\u4e8b\u9879\uff1a AVG() \u51fd\u6570\u5ffd\u7565 NULL \u503c\u3002 \u5982\u679c\u8ba1\u7b97\u4e2d\u6ca1\u6709\u6570\u5b57\u503c\uff08\u5373\u6240\u6709\u503c\u4e3a NULL\uff09\uff0c\u5219\u7ed3\u679c\u5c06\u4e3a NULL\u3002 \u5bf9\u4e8e\u5305\u542b\u8d1f\u6570\u7684\u6570\u5b57\u96c6\uff0cAVG() \u4f1a\u8fd4\u56de\u8d1f\u6570\u5e73\u5747\u503c\u3002 \u4ee5\u4e0a\u5c31\u662f\u5e73\u5747\u503c\u600e\u4e48\u6765\u7684\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-5465","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5465","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=5465"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5465\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}