我有一个如下表(示例数据)
http://sqlfiddle.com/#!18/21e55/1
我要进行超前和滞后运算,
条件1:-当前和以前(名称,月份和年份)相同且
条件2:-
A。如果存在阶段1和2,则计算
Stage number 2 = (Current row target value of stage 2 / previous row target value of stage 1)
B。如果存在阶段编号2,并且存在任何阶段编号(如阶段编号3或4或5),则计算
Stage number 3 = (Current row target value of stage 3 / previous row target value of stage number 2)
Stage number 4 = (Current row target value of stage 4 / previous row target value of stage number 2)
Stage number 5 = (Current row target value of stage 5 / previous row target value of stage number 2)
因此,我的输出应如下所示: http://sqlfiddle.com/#!18/8133c/1