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 -> Re: SQL Query To Establish Consecutive "Years"

Re: SQL Query To Establish Consecutive "Years"

From: Edward J. Prochak <ed.prochak_at_magicinterface.com>
Date: Mon, 18 Nov 2002 16:23:27 GMT
Message-ID: <3DD916C2.2070700@magicinterface.com>


Chris Battles wrote:
> I'm trying to construct a query that will find activity for a
> particular organization that has taken place in three consecutive
> "years" in the row (in this case the year is just a number and not a
> true date data type.) For example, to be valid we should find payments
> in 2002, 2001, and 2000.
>
> You usually join each of the tables by their primary keys as follows:
>
> SELECT name, req_amt, budgyear, pay_amt
> FROM Organization O, Request R, Payment P
> WHERE O.org_id = R.org_id AND
> R.req_id = P.req_id
> ORDER BY name, budgyer DESC;
>
> Each organization can have multiple requests and each request can have
> multiple payments.
>
> Here are the tables:
>
> Organization:
> -------------------------------
> ORG_ID NUMBER(10) NOT NULL (PRIMARY_KEY)
> NAME VARCHAR2(100)
>
> Request:
> -------------------------------
> REQ_ID NUMBER(10) NOT NULL (PRIMARY_KEY)
> ORG_ID NUMBER(10) NOT NULL (FOREIGN_KEY)
> REQ_AMT NUMBER(13,2)
>
> Payment:
> -------------------------------
> PAY_ID NUMBER(10) NOT NULL (PRIMARY_KEY)
> REQ_ID NUMBER(10) NOT NULL (FOREIGN_KEY)
> PAY_AMT NUMBER(13,2)
> BUDGYEAR NUMBER(4)
>
> Any help would be much appreciated. Thanks!

I'm sorry, but I don't see a problem here (other than for us to do your work for you). Did you try anything yet?

Seems like s simple enough query. What is your question?

HINT: where (BUDGYEAR = &&yearRequested
          or BUDGYEAR = &&yearRequested+1
          or BUDGYEAR = &&yearRequested-1)


-- 
Edward J. Prochak   --- Magic Interface, Ltd.
Ofc: 440-498-3700   --- 7295 Popham Place, Solon, OH 44139
on the web at       --- http://www.magicinterface.com
email: ed.prochak_at_magicinterface.com
Received on Mon Nov 18 2002 - 10:23:27 CST

Original text of this message

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