数据: 时间段 学员名称
2010-05-03 12:21:11 张三
2010-05-03 14:21:11 李四
2010-05-03 09:21:11 王五
问题:开始时间:2010-05-03 09
结束时间:2010-05-03 12
之间的数据,请高手帮帮忙
2010-05-03 12:21:11 张三
2010-05-03 14:21:11 李四
2010-05-03 09:21:11 王五
问题:开始时间:2010-05-03 09
结束时间:2010-05-03 12
之间的数据,请高手帮帮忙
select * from aaa where to_char(rq,'yyyymmdd') between '20011101' and '20020301';
直接在rq上加函数,如果应用大(这个表内数据很多时),查询速度会相当慢的,为了提高查询速度,强烈建议这样书写:
select * from aaa where rq between to_date('2001-11-01','yyyy-MM-DD') and to_date('2002-03-01' ,'YYYY-MM-DD');
推荐使用
select * from aaa where rq>;=to_date('2001-11-01','yyyy-MM-DD') and rq<=to_date('2002-03-01' ,'YYYY-MM-DD');用between的函数可能会慢些
from table1
where 时间段 between to_date('2010-05-03 09','yyyy-mm-dd hh24') and to_date('2010-05-03 12','yyyy-mm-dd hh24');
select 时间段,学员名称
from tb
where to_char(时间段,'yyyy-mm-dd hh24:mi:ss') between '2010-05-03 09:00:00' and '2010-05-03 12:00:00'
create table ss_csdn(
dateTime date,
stuName varchar2(20)
)select * from ss_csdn
insert into ss_csdn values (to_date('2010-05-03 12:21:11','yyyy-mm-dd hh24:mi:ss'),'张三');
insert into ss_csdn values (to_date('2010-05-03 14:21:11','yyyy-mm-dd hh24:mi:ss'),'李四');
insert into ss_csdn values (to_date('2010-05-03 11:21:11','yyyy-mm-dd hh24:mi:ss'),'王八');
insert into ss_csdn values (to_date('2010-05-03 09:21:11','yyyy-mm-dd hh24:mi:ss'),'王五');
select * from ss_csdn where datetime between to_date('2010-05-03 09:21:11','yyyy-mm-dd hh24:mi:ss')
and to_date('2010-05-03 12:21:11','yyyy-mm-dd hh24:mi:ss');