我需要以下sql小提琴的帮助:http://sqlfiddle.com/#!4/75813f/12。
这里我要在colmonth(1到5)的范围内填充ChannelValue
和foreach
列,其中colsumsum1
和colsumsum2
是colsumsum1
的值已经存在的地方。
例如对于colx = x1,应分别填充87和125,对于colx = x2,应分别填充58和96。
答案 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;