各位,帮帮忙,已经头痛了一个下午总是得不到想要的结果!

解决方案 »

  1.   

    过滤重复的用户名用distinc.如 select distinc username from usrs
    新建表用:create table tablename 
                     Fieldname dataclass datalength
      

  2.   

    to:wangorg() 
    这样我做过,用distinc卡号的话,其他字段的值不同的话卡号还是会重复,谢谢.
      

  3.   

    select Distinct A.学生编号,A.卡号,A.日期,A.操作时间 from 表一 A, 表二 B Where A.卡号 = A.卡号 AND not Exists (Select *  from 表一 Where 表一.学生编号=A.学生编号 AND 表一.日期 < A.日期 )
      

  4.   

    select Distinct A.学生编号,A.卡号,A.日期,A.操作时间 from 表一 A, 表二 B Where A.卡号 = B.卡号 AND not Exists (Select *  from 表一 Where 表一.学生编号=A.学生编号 AND 表一.日期 < A.日期 )
      

  5.   

    not Exists (Select *  from 表一 Where 表一.学生编号=A.学生编号 AND 表一.日期 < A.日期 )
    老冯还在吗?你这句是什么意思?
      

  6.   

    老冯Select *  from 表一 Where 表一.学生编号=A.学生编号 AND 表一.日期 < A.日期
    你这里的表一和A是不是同一个表?怎么多了一个A出来,?
      

  7.   

    select distinct 字段  from
    (select 字段 from a
    Union all
    select 字段 from b
    )即是新表
      

  8.   

    谢谢,但上面的都实现不了我想要的.
    我现在遇到了新的问题
    我的数据库是用ACCESS有个时间字段是短日期的 插入的时候就 时间一过16:00就出错.说是类型不匹配~~请各位帮帮忙
      

  9.   

    表:download
    卡号    日期        时间
    25478  2006-11-27  16:01
    25698  2006-11-27  18:01
    25568  2006-11-27  16:01
    25478  2006-11-27  16:01
    25568  2006-11-27  16:01
    25568  2006-11-27  18:01
    想要统计一下每一张卡号在某一时间段的打卡时间,只要最早的那条.插入一个新表.例如25568这个卡号就只要25568  2006-11-27  16:01这条记录.
    我自己写了个循环到这里时间条件一过16:00就出错:
    with ADOQuery2 do
                        begin
                          Close;
                          sql.Clear;
                          sql.Add('insert into 上课时间_temp select top 1 *  from download where download.卡号=:tempcard and 日期=:tempdate and 时间>=:amf and 时间<=:amt order by 时间 asc');
                          Parameters.ParamByName('amf').Value:=strtotime(amf);
                          Parameters.ParamByName('amt').Value:=strtotime(amt);
                          Parameters.ParamByName('tempdate').Value:=tempdate;
                          Parameters.ParamByName('tempcard').Value:=tempcard;
                          Execsql;
                          showmessage(amf);
                          Close;
                          sql.Clear;
                          sql.Add('insert into 上课时间_temp select top 1 *  from download where download.卡号=:tempcard and 日期=:tempdate and 时间>=:pm1f and 时间<=:pm1t order by 时间 asc');
                          Parameters.ParamByName('pm1f').Value:=strtotime(amf);
                          Parameters.ParamByName('pm1t').Value:=strtotime('16:00');//本来是strtotime(pm1t)的pm1t='18:00'
                          Parameters.ParamByName('tempdate').Value:=tempdate;
                          Parameters.ParamByName('tempcard').Value:=tempcard;
                          showmessage(pm1t);
                          Execsql;
                          Close;
                          sql.Clear;
                          sql.Add('insert into 上课时间_temp select top 1 *  from download where download.卡号=:tempcard and 日期=:tempdate and 时间>=:pm2f and 时间<=:pm2t');
                          Parameters.ParamByName('pm2f').Value:=strtotime(pm2f);
                          Parameters.ParamByName('pm2t').Value:=strtotime(pm2t);
                          Parameters.ParamByName('tempdate').Value:=tempdate;
                          Parameters.ParamByName('tempcard').Value:=tempcard;
                          Execsql;
      

  10.   

    我现在在外地客户这边,这里没有装Access. 待明天装ACCESS后,一定给你一个满意的答案。16:00的问题
    http://community.csdn.net/Expert/topic/5198/5198304.xml?temp=.430279
    明天一并测试。
      

  11.   

    谢谢老冯,这个问题今天早上我自己已经解决了.
    不过我想请问ACCESS中的短时间 在delphi中它会自动加上1899-12-31请问有没有办法解决?