I'm working on a timesheet tracking application - each time a person's hours are changed, a new row gets added to the database. The columns are timeid (int primary key), employmentid (int), hours (decimal 4,2) and payperiodid (int).
For each employment, I want to query the most recent hours for each payperiod.
Code:
SELECT hours,ppid,max(timeid) FROM hours WHERE employmentid=%d GROUP BY ppid