Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL Query To Establish Consecutive "Years"
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.comReceived on Mon Nov 18 2002 - 10:23:27 CST
![]() |
![]() |