oracle中在一张表存id1-id10,怎么一次关联查询出对应的名称?id1-id10都在一张表idInfo中。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle中在一张表存id1-id10,怎么一次关联查询出对应的名称?id1-id10都在一张表idInfo中。相关的知识,希望对你有一定的参考价值。

一张表为contentInfo列名为id1-id10,另一张表为idInfo,怎么关联把idInfo中的id对应名称name查出来?

参考技术A

必须通过idInfo表关联十次

select b.name,c.name,d.name,e.name,f.name,g.name,h.name,i.name,j.name,k.name
from
contentInfo a,
idInfo b,
idInfo c,
idInfo d,
idInfo e,
idInfo f,
idInfo g,
idInfo h,
idInfo i,
idInfo j,
idInfo k
where a.id1=b.id
and a.id2=c.id
and a.id3=d.id
and a.id4=e.id
and a.id5=f.id
and a.id6=g.id
and a.id7=h.id
and a.id8=i.id
and a.id9=j.id
and a.id10=k.id

本回答被提问者采纳

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中在一张表存id1-id10,怎么一次关联查询出对应的名称?id1-id10都在一张表idInfo中。的主要内容,如果未能解决你的问题,请参考以下文章

怎么样统计oracle DB一天数据增长量

oracle 中如何将一张500万数据的表从一个库快速转移到另外一个库

oracle中怎么如何把两张表中查询到的数据求和,

两张表 在一张表中插入数据时要使用触发器也更新另一张 有错误

SQL求助,我要想在一张表新增多行,只有第一列值不同,后面的列值相同,该怎么插入?

oracle中从一张表中筛选出不再多个时间段内的时间