Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Urgent! Programming Question ,(value of current date/value of prior date)

Urgent! Programming Question ,(value of current date/value of prior date)

From: Coca <bigmelon_at_btamail.net.cn>
Date: Fri, 26 Dec 2003 00:16:29 +0800
Message-ID: <bsf2h3$ci628$2@ID-189205.news.uni-berlin.de>


Hi all,

I am working on a project using Oracle9i and encounted a question as belows:

A Table like this:

create table account (sdate date,svalue numeric(16,2))



some records like:
sdate svalue
2003-1-1    2000
2003-2-1    3000
2003-3-1    3200
2003-4-1    1400
2003-5-1    2500
2003-6-1    2400


The records of the table follow this rule: only one record for one month, that is, each month has only one record.

The end-user could select any period of date as he will, such as from 2003-1-1 to 2003-4-1,
and my progrom should calculate a financial indicator called indicator1 whose formula is:
(value of current date/value of prior date), that is

sdate svalue indicator1

2003-1-1 2000 null(since the value of 2002-12-1 does not exist in the table)

2003-2-1   3000      3000/2000=1.5
2003-3-1   3200      3200/3000=1.067
2003-4-1   1400      1400/3200=0.4375

...

How can I do this using one sql sentence,not a stored procedure.

Any tips are appreciated.

Thank you.

Coca Received on Thu Dec 25 2003 - 10:16:29 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US