sql语句 时间段查询 高分

来源:百度知道 编辑:UC知道 时间:2024/05/22 19:57:25
sql server数据库里有表名recordtime, 里面有一列gettime为打卡时间列,格式为2008-10-10 8:00:00:000
现在想要根据一个时间段查询打卡记录,例如 ,我想查询2009-11-3到2009-12-3之间,8点到9点所有的打卡记录。
要求 输入日期,分别为“开始日期”和“结束日期”输入日期后,点查询按钮,即可查询开始日期到结束日期,8点到9点的所有打卡记录。
注:具体几点时间可以不用输入,直接在sql里。
非常想学习sql,希望大家多帮帮忙,本人会继续提升悬赏。谢谢大家。
本人是用asp开发的web程序。谢谢大家。
希望有个完整回答,谢谢

sql语句如下:
select 打卡记录 from recordtime
where (gettime>='开始时间' and gettime<='结束时间' )
and
(DATEPART(hh, gettime)>=8 and DATEPART(hh, gettime)<=9)
其中:打卡记录,是你具体要查询的信息的表中的字段,每个字段用逗号分隔,强烈建议你不要用“*”号
开始时间和结束时间即是WEB页面传进来的日期
我多加了两对括号只是便于理解
注意SQL语句中的所有的符合都要是英文输入法中的字符

假设开始的时间是begintiem,结束的时间是endtime
select * from recordtime where gettime>beginTime and gettime<endtime;
如:
select * from recordtime where gettime>'2009-11-3'and gettime<'2009-12-3';
而你begintime和endtime可以从界面取得然后传到sql语句中,你试试看吧!
祝你成功。。。
人家是sqlserver,而你写的是oracle,数据库错了!

select * from recordtime where gettime>='开始时间' and gettime<='结束时间' and DATEPART(hh, gettime)>=8 and DATEPART(hh, gettime)<=9

select count(*) from recordtime t where t.gettime between to_date('2009-11-3','yyyy-mm-dd')and to_date('2009-12-3','yyyy-mm-dd')