{"id":4988,"date":"2024-11-14T09:23:21","date_gmt":"2024-11-14T01:23:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/4988\/"},"modified":"2024-11-14T09:23:21","modified_gmt":"2024-11-14T01:23:21","slug":"oracle%e8%81%9a%e5%90%88%e5%87%bd%e6%95%b0%e6%80%8e%e4%b9%88%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/4988\/","title":{"rendered":"oracle\u805a\u5408\u51fd\u6570\u600e\u4e48\u4f7f\u7528"},"content":{"rendered":"<blockquote><p>\n  oracle \u805a\u5408\u51fd\u6570\u7528\u4e8e\u5c06\u6570\u636e\u503c\u7ec4\u5408\u6210\u5355\u4e2a\u503c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1aaggregate_function(expression) [over (partition by partition_expression order by order_expression)]\uff0c\u5176\u4e2d aggregate_function \u662f\u8981\u4f7f\u7528\u7684\u51fd\u6570\uff08\u5982 sum\u3001avg \u6216 count\uff09\uff0cexpression \u662f\u8981\u805a\u5408\u7684\u8868\u8fbe\u5f0f\uff0cpartition by \u548c order by \u6307\u5b9a\u6570\u636e\u5206\u7ec4\u548c\u805a\u5408\u8ba1\u7b97\u987a\u5e8f\u3002\u5e38\u7528\u51fd\u6570\u5305\u62ec sum\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052108452979620.jpg\" class=\"aligncenter\" title=\"oracle\u805a\u5408\u51fd\u6570\u600e\u4e48\u4f7f\u7528\u63d2\u56fe\" alt=\"oracle\u805a\u5408\u51fd\u6570\u600e\u4e48\u4f7f\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>Oracle \u4f7f\u7528\u6307\u5357<\/strong><\/p>\n<p>\u805a\u5408\u51fd\u6570\u7528\u4e8e\u5c06\u4e00\u7ec4\u503c\u7ec4\u5408\u6210\u5355\u4e2a\u503c\uff0c\u5982\u603b\u548c\u3001\u5e73\u5747\u503c\u6216\u8ba1\u6570\u3002Oracle \u6570\u636e\u5e93\u63d0\u4f9b\u4e86\u5e7f\u6cdb\u7684\u805a\u5408\u51fd\u6570\uff0c\u53ef\u7528\u4e8e\u5404\u79cd\u6570\u636e\u64cd\u4f5c\u4efb\u52a1\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528\u805a\u5408\u51fd\u6570<\/strong><\/p>\n<p>Oracle \u805a\u5408\u51fd\u6570\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>AGGREGATE_FUNCTION(expression) [OVER (PARTITION BY partition_expression ORDER BY order_expression)]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>AGGREGATE_FUNCTION \u662f\u8981\u4f7f\u7528\u7684\u805a\u5408\u51fd\u6570\uff0c\u4f8b\u5982 SUM\u3001AVG \u6216 COUNT\u3002<\/li>\n<li>expression \u662f\u8981\u8ba1\u7b97\u805a\u5408\u7684\u8868\u8fbe\u5f0f\u3002<\/li>\n<li>PARTITION BY \u5b50\u53e5\u5c06\u6570\u636e\u5206\u7ec4\u5230\u5206\u533a\u4e2d\uff0c\u4ee5\u4fbf\u5728\u6bcf\u4e2a\u5206\u533a\u4e0a\u8ba1\u7b97\u805a\u5408\u3002<\/li>\n<li>ORDER BY \u5b50\u53e5\u6307\u5b9a\u5206\u533a\u5185\u805a\u5408\u8ba1\u7b97\u7684\u987a\u5e8f\u3002<\/li>\n<\/ul>\n<p><strong>\u5e38\u7528\u805a\u5408\u51fd\u6570<\/strong><\/p>\n<p>Oracle \u4e2d\u6700\u5e38\u7528\u7684\u805a\u5408\u51fd\u6570\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>SUM(): \u8ba1\u7b97\u4e00\u7ec4\u503c\u7684\u603b\u548c\u3002<\/li>\n<li>AVG(): \u8ba1\u7b97\u4e00\u7ec4\u503c\u7684\u5e73\u5747\u503c\u3002<\/li>\n<li>COUNT(): \u8ba1\u7b97\u4e00\u7ec4\u503c\u7684\u8ba1\u6570\u3002<\/li>\n<li>MIN(): \u67e5\u627e\u4e00\u7ec4\u503c\u7684\u6700\u5c0f\u503c\u3002<\/li>\n<li>MAX(): \u67e5\u627e\u4e00\u7ec4\u503c\u7684\u6700\u5927\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\u7528\u6cd5<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u663e\u793a\u4e86\u5982\u4f55\u4f7f\u7528 SUM() \u805a\u5408\u51fd\u6570\u8ba1\u7b97\u8868\u4e2d\u6240\u6709\u8ba2\u5355\u7684\u603b\u91d1\u989d\uff1a<\/p>\n<pre>SELECT SUM(order_amount)\nFROM orders;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u663e\u793a\u4e86\u5982\u4f55\u4f7f\u7528 AVG() \u805a\u5408\u51fd\u6570\u8ba1\u7b97\u6bcf\u4f4d\u5ba2\u6237\u7684\u5e73\u5747\u8ba2\u5355\u91d1\u989d\uff1a<\/p>\n<pre>SELECT customer_id, AVG(order_amount)\nFROM orders\nGROUP BY customer_id;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u7a97\u53e3\u51fd\u6570<\/strong><\/p>\n<p>Oracle \u805a\u5408\u51fd\u6570\u8fd8\u53ef\u4ee5\u4e0e\u7a97\u53e3\u51fd\u6570\u7ed3\u5408\u4f7f\u7528\uff0c\u7a97\u53e3\u51fd\u6570\u5141\u8bb8\u5728\u6570\u636e\u96c6\u4e2d\u884c\u7684\u8303\u56f4\u5185\u6267\u884c\u8ba1\u7b97\u3002\u4ee5\u4e0b\u793a\u4f8b\u663e\u793a\u4e86\u5982\u4f55\u4f7f\u7528 SUM() \u805a\u5408\u51fd\u6570\u548c OVER() \u7a97\u53e3\u51fd\u6570\u8ba1\u7b97\u6bcf\u4e2a\u5ba2\u6237\u5728\u8fc7\u53bb 30 \u5929\u5185\u7684\u8ba2\u5355\u603b\u91d1\u989d\uff1a<\/p>\n<pre>SELECT customer_id, SUM(order_amount) OVER (PARTITION BY customer_id ORDER BY order_date ROWS BETWEEN INTERVAL '30 days' PRECEDING AND CURRENT ROW)\nFROM orders;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u4f7f\u7528\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>oracle \u805a\u5408\u51fd\u6570\u7528\u4e8e\u5c06\u6570\u636e\u503c\u7ec4\u5408\u6210\u5355\u4e2a\u503c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1aaggregate_function(expression) [over (partition by partition_expression order by order_expression)]\uff0c\u5176\u4e2d aggregate_function \u662f\u8981\u4f7f\u7528\u7684\u51fd\u6570\uff08\u5982 sum\u3001avg \u6216 count\uff09\uff0cexpression \u662f\u8981\u805a\u5408\u7684\u8868\u8fbe\u5f0f\uff0cpartition by \u548c order by \u6307\u5b9a\u6570\u636e\u5206\u7ec4\u548c\u805a\u5408\u8ba1\u7b97\u987a\u5e8f\u3002\u5e38\u7528\u51fd\u6570\u5305\u62ec sum Oracle \u4f7f\u7528\u6307\u5357 \u805a\u5408\u51fd\u6570\u7528\u4e8e\u5c06\u4e00\u7ec4\u503c\u7ec4\u5408\u6210\u5355\u4e2a\u503c\uff0c\u5982\u603b\u548c\u3001\u5e73\u5747\u503c\u6216\u8ba1\u6570\u3002Oracle \u6570\u636e\u5e93\u63d0\u4f9b\u4e86\u5e7f\u6cdb\u7684\u805a\u5408\u51fd\u6570\uff0c\u53ef\u7528\u4e8e\u5404\u79cd\u6570\u636e\u64cd\u4f5c\u4efb\u52a1\u3002 \u5982\u4f55\u4f7f\u7528\u805a\u5408\u51fd\u6570 Oracle \u805a\u5408\u51fd\u6570\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a AGGREGATE_FUNCTION(expression) [OVER (PARTITION BY partition_expression ORDER BY order_expression)] \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a AGGREGATE_FUNCTION \u662f\u8981\u4f7f\u7528\u7684\u805a\u5408\u51fd\u6570\uff0c\u4f8b\u5982 SUM\u3001AVG \u6216 COUNT\u3002 expression \u662f\u8981\u8ba1\u7b97\u805a\u5408\u7684\u8868\u8fbe\u5f0f\u3002 PARTITION BY \u5b50\u53e5\u5c06\u6570\u636e\u5206\u7ec4\u5230\u5206\u533a\u4e2d\uff0c\u4ee5\u4fbf\u5728\u6bcf\u4e2a\u5206\u533a\u4e0a\u8ba1\u7b97\u805a\u5408\u3002 ORDER BY \u5b50\u53e5\u6307\u5b9a\u5206\u533a\u5185\u805a\u5408\u8ba1\u7b97\u7684\u987a\u5e8f\u3002 \u5e38\u7528\u805a\u5408\u51fd\u6570 Oracle \u4e2d\u6700\u5e38\u7528\u7684\u805a\u5408\u51fd\u6570\u5305\u62ec\uff1a SUM(): [&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-4988","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4988","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=4988"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4988\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=4988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=4988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=4988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}