djpingpong
Programmer
- Jul 6, 2004
- 70
So I have 2 tables:
PERSON -> is a table of basic info regarding members in the company (unique key here is PERSON_ID)
sample records:
PERSON_ID DEPT
123 abc
111 abc
100 bdc
200 cda
140 abc
EARN_HIST -> is a table of historical earnings for each member (unique key here is PERSON_ID, EARN_DATE) and has a 1-to-many relationship to PERSON table
sample records:
PERSON_ID EARN_DATE EARNINGS
123 2002/1/1 $1000
123 2010/1/1 $2000
100 2009/1/1 $15000
100 2011/1/1 $10000
111 2008/1/1 $5000
111 2008/7/1 $7000
111 2012/1/1 $10000
140 2010/6/1 $5000
140 2010/12/1 $7500
etc, etc, etc
My goal is to retrieve the most current Earning record for each member where DEPT = 'abc'
so my expected result is:
PERSON_ID EARN_DATE EARNINGS
123 2010/1/1 $2000
111 2008/7/1 $7000
140 2010/12/1 $7500
can this be done be just a query? or do I have to define a Store Procedure and/or Function to achieve my results?
any help on this would be greatly appreciated
PERSON -> is a table of basic info regarding members in the company (unique key here is PERSON_ID)
sample records:
PERSON_ID DEPT
123 abc
111 abc
100 bdc
200 cda
140 abc
EARN_HIST -> is a table of historical earnings for each member (unique key here is PERSON_ID, EARN_DATE) and has a 1-to-many relationship to PERSON table
sample records:
PERSON_ID EARN_DATE EARNINGS
123 2002/1/1 $1000
123 2010/1/1 $2000
100 2009/1/1 $15000
100 2011/1/1 $10000
111 2008/1/1 $5000
111 2008/7/1 $7000
111 2012/1/1 $10000
140 2010/6/1 $5000
140 2010/12/1 $7500
etc, etc, etc
My goal is to retrieve the most current Earning record for each member where DEPT = 'abc'
so my expected result is:
PERSON_ID EARN_DATE EARNINGS
123 2010/1/1 $2000
111 2008/7/1 $7000
140 2010/12/1 $7500
can this be done be just a query? or do I have to define a Store Procedure and/or Function to achieve my results?
any help on this would be greatly appreciated