Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle SQL添加列,总列按其他字段分组_Sql_Oracle12c - Fatal编程技术网

Oracle SQL添加列,总列按其他字段分组

Oracle SQL添加列,总列按其他字段分组,sql,oracle12c,Sql,Oracle12c,我有这个结果 ZONE SITE BRAND VALUE north a a_brand1 10 north a a_brand2 15 north a a_brand3 27 south b b_brand1 17 south b b_brand2 5 south b b_brand3 56 是否有任何方法可以添加一列,其中包含按区域和站点分组

我有这个结果

ZONE    SITE    BRAND    VALUE
north    a      a_brand1    10
north    a      a_brand2    15
north    a      a_brand3    27
south    b      b_brand1    17
south    b      b_brand2    5
south    b      b_brand3    56
是否有任何方法可以添加一列,其中包含按区域和站点分组的总和?这样:总场地a=10+15+27=52,总场地b=17+5+56=78

ZONE    SITE    BRAND    VALUE    TOTAL_IN_SITE
north    a      a_brand1    10         52
north    a      a_brand2    15         52
north    a      a_brand3    27         52
south    b      b_brand1    17         78
south    b      b_brand2    5          78
south    b      b_brand3    56         78

谢谢。

使用
sum
窗口功能

select t.*,sum(val) over(partition by zone,site) 
from tbl t

使用
sum
窗口函数

select t.*,sum(val) over(partition by zone,site) 
from tbl t

美好的非常感谢。很好!。谢谢。