I have a need to display a sequence number column in a table that lists the count of each record for a person in a Job history table. Each history record has a Job Start Date and the number should be listed in the chronological order of the dates.
This is how I want it to look-
EmployeeID SeqNo. JobStartDate
A0001 1 2006/02/02
A0001 2 2008/04/01
A0001 3 2009/03/01
A0002 1 2005/01/01
A0002 2 2005/04/01
A0003 1 2006/09/01
A0003 2 2007/01/01
A0003 3 2008/01/01
If you are using SQL Server 2005+ or any other version of SQL that supports
ROW_NUMBER() and PARTITIONthen you can do something like thisThe row_number creates a unique row based on the partition (which acts like a GROUP BY) and the ORDER BY.