-- Operation Log table
Create Table Joblog -- Operation Log table
(
Joblogid] Int Not Null , -- Primary Key
Functionid Nvarchar ( 20 ) Null , -- Function ID
Operatetime Datetime Null -- Operation Time
) On Primary
Go
Alter Table Joblog Add
Constraint Pk_joblog Primary Key Clustered (Joblogid) On Primary
Go
-- All records in the operation log table
Select * From Joblog
Query results:
1 001 2007 - 11 - 01
2 001 2007 - 11 - 02
3 001 2007 - 11 - 03
4 002 2007 - 11 - 04
5 002 2007 - 11 - 05
6 003 2007 - 11 - 06
7 004 2007 - 11 - 07
8 004 2007 - 11 - 08
9 005 2007 - 11 - 09
10 005 2007 - 11 - 10
-- Last operation record of each function
Select * From Joblog
Where Joblogid In
( Select Top 1 Joblogid From Joblog
Where A. functionid = Functionid Order By Operatetime Desc
)
Query results:
3 001 2007 - 11 - 03
5 002 2007 - 11 - 05
6 003 2007 - 11 - 06
8 004 2007 - 11 - 08
10 005 2007 - 11 - 10