我的table如下。
WITH mytable as (
select 1 as serial, 'm1' as m, 10 as p, null as q from dual
union
select 2, 'm1', 12, null from dual
union
select 3, 'm1', null, 5 from dual
union
select 4, 'm2', 20 , null from dual
union
select 5, 'm1', null, 6 from dual
union
select 6, 'm2', null, 4 from dual
) select * from mytable;
我的目标是把p除以q。问题是命名符和分母不在同一行中。此外,对于每个命名器和分母,我希望使用m划分的串行列中具有高值的行。预期结果是
M Calculated_value
--- ----------------
m1 2 <--- 12 at the serial 2 divided by 6 in the rownumber 5
m2 5 <--- 20 " 4 " 5 6
3条答案
按热度按时间rta7y2nd1#
这里有一个选择;您可能需要的代码从第14行开始:
piv4azn72#
看起来你需要这个:
完整示例:
yc0p9oo03#