beckhambobo(beckham) 请您来看一下这个你回答过的问题
http://expert.csdn.net/expert/topic/2178/2178818.xml?temp=.7840387
您的答案是:
select quantity from
(select sum(quantity) over(order by rownum) quantity from table1)
order by quantity desc
对于这条sql语句我不太明白,特别是over这一段,我查书也没查到,到google上也没有找到,能麻烦您给我解释一下吗? 谢谢
为了能让这个问题被解答,请同样想知道的同志顶一下!
推荐阅读
the following example calculates, for each manager, a cumulative total of salaries of employees who answer to that manager that are equal to or less than the current salary:
select mgr, ename, sal,
sum(sal) over (partition by mgr order by sal
range unbounded preceding) l_csum
from emp;
mgr ename sal l_csum
---------- ---------- ---------- ----------
7566 scott 3000 6000
7566 ford 3000 6000
7698 james 950 950
7698 ward 1250 3450
7698 martin 1250 3450
7698 turner 1500 4950
7698 allen 1600 6550
7782 miller 1300 1300
7788 adams 1100 1100
7839 clark 2450 2450
7839 blake 2850 5300
7839 jones 2975 8275
7902 smith 800 800
king 5000 5000
over是分析函数一个关键字,就上面例子作一个解释吧。
查询以mgr作分组,以sql作升序对sql进行累加,存在分组就是组别内进行累加,不存在分组就以整条记录集进行累加,这个地方要注意.排序是某字段作一个升或降进行排位。


讨论区