如果用一条sql语句将一个表中的字段信息作为另一个表的查询字段进行查询

ygc8163 2007-11-01 11:32:42
比如A表中有 field 这个字段,字段里面有以下数据 ID,name,age
B表中有ID,name,age字段 如何在A表中取出字段名在B表中查询

相当于select id,name,age from b
...全文
317 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
meiZiNick 2008-05-01
  • 打赏
  • 举报
回复
我也想了解,谢谢LZ.
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
接分先!
cafedelmar 2007-12-04
  • 打赏
  • 举报
回复
可以使用pl/sql的动态sql拼sql语句
chiyt 2007-12-04
  • 打赏
  • 举报
回复
select id,name,age from B
where (id||','||name||','||age) in
(select field from A);
ygc8163 2007-11-22
  • 打赏
  • 举报
回复
按照楼上这种说法,还是已经知道了b表中有哪些字段了,如果我要在a表中去状态位字段state为1的的field作为查询表b的的字段,那不是没有办法了。
gxlineji 2007-11-01
  • 打赏
  • 举报
回复

create table A
(field varchar2(10));

insert into a select 'id'from dual union
select 'name'from dual union
select 'age' from dual

create table b
(id varchar2(10),
name varchar2(10),
age varchar2(10));

insert into b select '100','aa','21' from dual union
select '101','bb','22' from dual union
select '102','cc','23' from dual

select sum(decode(field,'id',b.id)) as id,max(decode(field,'name',b.name)) as name,
max(decode(field,'age',b.age)) as age from a,b
where id=b.id
group by b.id


ID NAME AGE
---------- ---------- ---------
100 aa 21
101 bb 22
102 cc 23

3,490

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧