表A:
name date
A 2006-1-2
B 2006-1-2
A 2006-1-3
C 2006-1-2
得到以下结果:
name date
A 2006-1-2
B 2006-1-2
C 2006-1-2
name date
A 2006-1-2
B 2006-1-2
A 2006-1-3
C 2006-1-2
得到以下结果:
name date
A 2006-1-2
B 2006-1-2
C 2006-1-2
Insert @t select 'a','2006-1-2'
Union all select 'b','2006-1-2'
Union all select 'a','2006-1-3'
Union all select 'c','2006-1-2'---
Select * From @t A
Where Not Exists
(Select 1 From @t Where Name=A.Name and Date<A.Date)
Select Name,Min(Date) as date
From @t
Group By Name
SELECT DISTINCT name ,date