请教求和汇总后字段插入原表中的语句

解决方案 »

  1.   

    请教求和汇总后字段插入原表中的语句
    有如下tran数据
    date             account    type    amount
    20160101       123            cun      100
    20160101       123            cun      200
    20160101       123            qu        400
    20160203       456            cun      100
    20160203       456            cun      400希望按date account type 对 amount求和后将结果放在最后一列输出如下date             account    type    amount     total
    20160101       123            cun      100      300
    20160101       123            cun      200      300
    20160101       123            qu        400      400
    20160203       456            cun      100      500
    20160203       456            cun      400      500请问如何写上述语句,使用嵌套或link方式吗 ,如何写呀?谢谢各位大神
      

  2.   

    select date,account,type,amount,sum(amount) over (partition by date,account,type) as total from tran
      

  3.   

    如果你只是想查询一下
    按 2# 的方法如果你要更新到原表中 ,另 一个帖子给你回复了,,用这个方法
    http://bbs.csdn.net/topics/391949112#post-401128460
      

  4.   

    非常感谢,但是没有看懂over(parrtition date,account,type)含义,不知道是否用group呀?请恕我无知,谢谢
      

  5.   

    非常感谢,但是没有看懂over(parrtition date,account,type)含义,不知道是否用group呀?请恕我无知,谢谢
    喔,我查了一下,over是一种分析函数,分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是对于每个组返回多行,而聚合函数对于每个组只返回一行。 
    谢谢