VB+ACCESS
ACCESS数据库一表中按时间顺序有一万多条记录,时间的跨度在两年时间左右,就是一天时间内有20左右条记录,我现在用两个dtpicker控件(一个查询起始时间,一个结束时间)可以查出一个时间段时的数据,但我要进一步对这些数据进行筛选,按时间顺序找出每天的最后一条记录,就是说比如我用DTPICKER控件查询出来2005-10-10到2005-11-18这段时间内的所有数据,再次进行筛选只留下每天时间字段值最大的那条记录,最后在这段时间内筛选出40条记录。

解决方案 »

  1.   

    select Max(Date),Max(Time) From Table1 Where (Date Between '2005-10-10' And '2005-11-18') Group By Date
      

  2.   

    select top 40 Date,Max(Time) From Table1 Where (Date Between '2005-10-10' And '2005-11-18') Group By Date
      

  3.   

    select top 40 Date,Max(Time) From Table1 Where (Date Between #2005-10-10# And #2005-11-18#) Group By Date
      

  4.   

    以上的方法都实现不了,首先40这个数字不是回定的它会随着输入查询时间的范围的变化而变化,再有max(time)这个函数应该行不通,每天最后一条记录的时间是不一样的,一两条语句可能实现不了这个功能。
    再问一个问题
    rs.addnew用于增加一条新记录
    rs.delete用于删除记录
    要是要删除一个表中的所有记录应该怎么写?
    我这是样写的:rs.delete([affectrecords as actionenum=adaffectall])
    增加记录都没问题,DELETE不加后面的参数会删除第一条记录,加上后面的参数就不行了不知是什么原因?
      

  5.   

    要是要删除一个表中的所有记录应该怎么写?不要用 recordset 对象,用 connection 对象:
    rs.activeconnection.execute "delete from 表名"
      

  6.   

    虽然每天最后一条记录的时间是不一样的,但是用Max函数配合Group By 就可以实现你的要求:
    select top 40 [Date],Max([Time]) From Table1 Where ([Date] Between #2005-10-10# And #2005-11-18#) Group By [Date]要是要删除一个表中的所有记录应该怎么写?
    --------------------------------------
    cn.Execute "Delete From 表"
      

  7.   

    不知道你的字段是怎么设置的,比如有日期字段dates,时间字段times,则试试如下语句:
    select top 40 a.*
    from tb a,(select dates,max(times) as t from tb group by dates) b
    where a.dates=b.dates and a.times=b.t
    and dates between #2005-10-10# and #2005-11-18#
      

  8.   

    select top 40 a.*
    from tb a,(select dates,max(times) as t from tb group by dates) b
    where a.dates=b.dates and a.times=b.t
    and a.dates between #2005-10-10# and #2005-11-18#