Home » SQL & PL/SQL » SQL & PL/SQL » Cummulative selection
Cummulative selection [message #238138] Wed, 16 May 2007 17:18 Go to next message
ashokkr24
Messages: 8
Registered: January 2007
Location: Chennai
Junior Member
Hi,
I have a table meter in the following format.

------------
Day Meter
------------
1 100
2 150
3 170
4 180
5 185
. .
. .
. .
-----------
I have to retrieve the record in the cummulative fashion as follows ...
------------
Day Meter
------------
1 100
2 50
3 20
4 10
5 5
. .
. .
. .
------------

TIA
Ashok
Re: Cummulative selection [message #238167 is a reply to message #238138] Wed, 16 May 2007 22:29 Go to previous messageGo to next message
flyboy
Messages: 1832
Registered: November 2006
Senior Member
Hi,
use the LAG function.
Re: Cummulative selection [message #238354 is a reply to message #238138] Thu, 17 May 2007 09:52 Go to previous messageGo to next message
ashokkr24
Messages: 8
Registered: January 2007
Location: Chennai
Junior Member
Thanks for ur reply.
But I beleive the LAG function provides different result.

Actually, the logic is to find the amount of units used on the corresponding day.

Any help.

TIA,
Ashok.


Re: Cummulative selection [message #238358 is a reply to message #238354] Thu, 17 May 2007 10:18 Go to previous message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
And the LAG function allows to retrieve the value of the previous row along with the value of the current row.
I think just subtract the two will give you what you wanted.

Regards
Michel
Previous Topic: SQL query do not show all records ...
Next Topic: how to use an cursor for loop
Goto Forum:
  


Current Time: Sat Dec 10 07:15:50 CST 2016

Total time taken to generate the page: 0.14265 seconds