Oracle SQL总和

时间:2018-09-04 18:58:05

标签: sql oracle

我需要以下sql小提琴的帮助:http://sqlfiddle.com/#!4/75813f/12

这里我要在colmonth(1到5)的范围内填充ChannelValueforeach列,其中colsumsum1colsumsum2colsumsum1的值已经存在的地方。

例如对于colx = x1,应分别填充87和125,对于colx = x2,应分别填充58和96。

1 个答案:

答案 0 :(得分:1)

您需要更改PARTITION BY中的列:

select 
  nvl(demo.colx, blamth.colx) as colx,
  nvl(demo.cola, blamth.cola) as cola,
  nvl(demo.colb, blamth.colb) as colb,
  nvl(demo.colc, blamth.colc) as colc,
  nvl(demo.colmonth, blamth.colmonth) as colmonth,
  nvl(demo.colsum1, 0) as colsum1,
  nvl(demo.colsum2, 0) as colsum2,
  sum(nvl(demo.colsum1, 0)) over (partition by blamth.colx) as colsumsum1,
  sum(nvl(demo.colsum2, 0)) over (partition by blamth.colx) as colsumsum2  
from demo right outer join blamth
on demo.colx = blamth.colx and
   demo.colmonth = blamth.colmonth
order by 1,5;

DBFiddle Demo