create table temp (month date , outstanding number);
insert into temp values(to_date('01/05/2012','dd/mm/yyyy'),35678956);
insert into temp values(to_date('02/05/2012','dd/mm/yyyy'),33678956);
insert into temp values(to_date('03/05/2012','dd/mm/yyyy'),31678956);
insert into temp values(to_date('04/05/2012','dd/mm/yyyy'),27678956);
insert into temp values(to_date('05/05/2012','dd/mm/yyyy'),24678956);
insert into temp values(to_date('01/06/2012','dd/mm/yyyy'),44678956);
insert into temp values(to_date('02/06/2012','dd/mm/yyyy'),41678956);
FIRST_VALUE
分析函数在first record
执行完之后从分区中选择ORDER BY
SELECT month
,outstanding
,outstanding/(FIRST_VALUE(outstanding)
OVER (PARTITION BY to_char(month,'mm')
ORDER BY month
)) as ratio
FROM temp
ORDER BY month;
输出
MONTH OUTSTANDING RATIO
--------- ----------- ----------
01-MAY-12 35678956 1
02-MAY-12 33678956 .943944548
03-MAY-12 31678956 .887889096
04-MAY-12 27678956 .775778193
05-MAY-12 24678956 .691695015
01-JUN-12 44678956 1
02-JUN-12 41678956 .932854295
选择了 7 行。
SQLFIDDLE 链接