Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Query Help

Status
Not open for further replies.

gottaski

Programmer
Jan 4, 2001
17
US
I have a table w/ the following fields:

EmpID | Salary | Month-Year

with data such as:

2134 | $50,000 | Jan-01
2134 | $80,000 | Feb-01
2134 | $75,000 | Mar-01
2134 | $0 | Apr-01

2135 | $50,000 | Jan-01
2135 | $80,000 | Feb-01
2135 | $80,000 | Mar-01
2135 | $80,000 | Apr-01

What I need to do is select the Employee's last salary and last month of employment.

Result of Query:

EmpID | Last Salary | Last Month
2134 | $75,000 | Mar-01
2135 | $80,000 | Apr-01

Anyone out there have any suggestions? Any help would be greatly appreciated! Thanks!
 
What about this:

SELECT yourtable.Emp,
Last(yourtable.Empdt) AS LastOfEmpdt,
Last(yourtable.Salary) AS LastOfSal
FROM yourtable
WHERE yourtable.Salary <> 0
GROUP BY yourtable.Emp
ORDER BY yourtable.Emp;

Assuming these are chronological ** or if you really want the highest value... use MAX
J. Jones
jjones@cybrtyme.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top