Home » SQL & PL/SQL » SQL & PL/SQL » fetching the previous sum and current sum
fetching the previous sum and current sum [message #2556] Thu, 25 July 2002 22:02 Go to next message
Deepa
Messages: 269
Registered: November 2000
Senior Member
hi,
if i give group by function to give the sum(sal) from emp ,it has to fetch the previous sum also along with current sum.

regards,
deepa
Re: fetching the previous sum and current sum [message #2562 is a reply to message #2556] Fri, 26 July 2002 10:36 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Same concept as in my answer to your previous question.

sql>select deptno, sum(sal),
  2         lag(sum(sal), 1, sum(sal)) over (order by deptno) previous_sumsal
  3    from emp
  4   group by deptno;
 
   DEPTNO  SUM(SAL) PREVIOUS_SUMSAL
--------- --------- ---------------
       10      8750            8750
       20     10875            8750
       30      9400           10875
Previous Topic: Re: Creating a user in a stored procedure - compile error
Next Topic: Custom Month-to-date Expression
Goto Forum:
  


Current Time: Tue Apr 23 11:25:58 CDT 2024