Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> SQL Query To Establish Consecutive "Years"
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:
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)
![]() |
![]() |