oracle中从一张表中筛选出不再多个时间段内的时间
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle中从一张表中筛选出不再多个时间段内的时间相关的知识,希望对你有一定的参考价值。
一张表存储 假期 开始时间strat_time 结束时间 end_time,这张表中存储有多条记录
另一张表存储正常的时间work_time
如何从存储正常时间的的表中筛选出不再另一张表包含的时间段内的时间
create table table_a( t1 date, t2 date);
insert into table_a values(to_date('20140501','yyyymmdd') ,to_date('20140503','yyyymmdd'));
insert into table_a values(to_date('20140508','yyyymmdd') ,to_date('20140509','yyyymmdd'));
create table table_b(t date,id int)
insert into table_b values(to_date('20140501','yyyymmdd'),1);
insert into table_b values(to_date('20140502','yyyymmdd'),2);
insert into table_b values(to_date('20140503','yyyymmdd'),3);
insert into table_b values(to_date('20140504','yyyymmdd'),4);
insert into table_b values(to_date('20140505','yyyymmdd'),5);
insert into table_b values(to_date('20140506','yyyymmdd'),6);
insert into table_b values(to_date('20140507','yyyymmdd'),7);
insert into table_b values(to_date('20140508','yyyymmdd'),8);
insert into table_b values(to_date('20140509','yyyymmdd'),9);
insert into table_b values(to_date('20140510','yyyymmdd'),10);
insert into table_b values(to_date('20140511','yyyymmdd'),11);
查询语句
select * from table_b where t not in(
select distinct b.t from table_b b,table_a a where b.t between a.t1 and a.t2) 参考技术A oracle中从一张表中筛选出不再多个时间段内的时间
建表和插入数据
create table table_a( t1 date, t2 date);
insert into table_a values(to_date('20140501','yyyymmdd') ,to_date('20140503','yyyymmdd'));
insert into table_a values(to_date('20140508','yyyymmdd') ,to_date('20140509','yyyymmdd'));
create table table_b(t date,id int)
insert into table_b values(to_date('20140501','yyyymmdd'),1);
insert into table_b values(to_date('20140502','yyyymmdd'),2);
insert into table_b values(to_date('20140503','yyyymmdd'),3);
insert into table_b values(to_date('20140504','yyyymmdd'),4);
insert into table_b values(to_date('20140505','yyyymmdd'),5);
insert into table_b values(to_date('20140506','yyyymmdd'),6);
insert into table_b values(to_date('20140507','yyyymmdd'),7);
insert into table_b values(to_date('20140508','yyyymmdd'),8);
insert into table_b values(to_date('20140509','yyyymmdd'),9);
insert into table_b values(to_date('20140510','yyyymmdd'),10);
insert into table_b values(to_date('20140511','yyyymmdd'),11);
查询语句
select * from table_b where t not in(
select distinct b.t from table_b b,table_a a where b.t between a.t1 and a.t2)
以上是关于oracle中从一张表中筛选出不再多个时间段内的时间的主要内容,如果未能解决你的问题,请参考以下文章