vb 查询时间数据最后一个

来源:百度知道 编辑:UC知道 时间:2024/05/22 08:34:09
我要做一个类似考勤的程序,ACCESS数据库中每天有很多的打卡时间数据,我的问题是:比如查询1月份中每天最后的打卡数据怎么查询?

为什么我只能读出来查询时间段中的最后一条数据
而不是每天的数据?
没有错 ,我是要查每天最后一条数据.
我现在的代码是rs.Open "select right(PunchTime,8)as a,EmpName from DoorPunch where EmpName='" & Text1.Text & "'and PunchTime between #" & t1 & " # and #" & t2 & "# group by PunchTime,EmpName order by PunchTime asc ", cn, adOpenKeyset
上面这句来查询 right(PunchTime,8) 是每天打卡的数据 我这样查是显示查询时间段中每天所有的数据,但是我只要查询时间段中每天的最后一个数据

ttkk = "select * from (SELECT Max(PunchTime) as ttt, Max(EmpName) as mmm FROM DoorPunch where PunchTime between #" & t1 & " # and #" & t2 & "# GROUP BY Year(PunchTime), Month(PunchTime), Day(PunchTime)) Where mmm = '" & Text1.Text & "'"
rs.Open ttkk, cn, adOpenKeyset

终于搞定了
原理是这样的
分两次查询
先(SELECT Max(PunchTime) as ttt, Max(EmpName) as mmm FROM DoorPunch where PunchTime between #" & t1 & " # and #" & t2 & "# GROUP BY Year(PunchTime), Month(PunchTime), Day(PunchTime)查出全部每天最后一名

你要写31个子表来取每一天最大的一个!~

代码不多 写一个for循环就可以!~

不会的话来找我吧 求求 六五三八一三三九

查询出来的记录按时间升序排个序,然后读取最后一个记录就可以了
SELECT * FROM 你的表 WHERE 时间 BETWEEN 开始 AND 结束 ORDER BY 时间 ASC