表: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;
新建表用:create table tablename
Fieldname dataclass datalength
这样我做过,用distinc卡号的话,其他字段的值不同的话卡号还是会重复,谢谢.
老冯还在吗?你这句是什么意思?
你这里的表一和A是不是同一个表?怎么多了一个A出来,?
(select 字段 from a
Union all
select 字段 from b
)即是新表
我现在遇到了新的问题
我的数据库是用ACCESS有个时间字段是短日期的 插入的时候就 时间一过16:00就出错.说是类型不匹配~~请各位帮帮忙
卡号 日期 时间
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;
http://community.csdn.net/Expert/topic/5198/5198304.xml?temp=.430279
明天一并测试。
不过我想请问ACCESS中的短时间 在delphi中它会自动加上1899-12-31请问有没有办法解决?