I have a table with three columns as so: username (varchar32), punch_type (enum), and punch_date_time (timestamp). Given a date, how can I extract the last punch before a given timestamp for each user? More specifically, I'm building a new timeclock system for my employer. Given a date, I need to know the last action on the timeclock for each user that occurred before the start of the new pay period.
I have something functional but it requires logic in the script and multiple queries to make it happen. Since all of the requisite information is in the database, I don't see why I shouldn't be able to extract thei nformation I'm looking for in one query. If it helps, I have another table of employee usernames that I might be able to use in a join of some sort to isolate these timeclock records.