1. 随便做个查询称为 “结果”
2
Private Sub Command4_Click()
Dim qdf As DAO.QueryDef
Dim strSQL As String
If Not IsNull(Me.Text2) Then
strSQL = _
"select * from sheet1 where id in (select distinct myid from (SELECT a.姓名, a.开始日期, (select top 1 b.id from sheet1 b where b.姓名=a.姓名 and b.开始日期<=#" _
& Me.Text2 & "# order by b.开始日期 desc) as myId FROM Sheet1 AS a))"
Set qdf = CurrentDb.QueryDefs("结果")
qdf.SQL = strSQL
Me.She.SourceObject = "查询.结果"
qdf.Close
Set qdf = Nothing
End If
End Sub
select *
from sheet1
where id in (select distinct myid from (SELECT a.姓名, a.开始日期,
(select top 1 b.id from sheet1 b where b.姓名=a.姓名 and b.开始日期<=#2002/3/1# order by b.开始日期 desc) as myId
from sheet1 AS a))