org表有org_id(组织) org_name(组织名称),parent_id (父组织编号)。表中存储的数据时这样的:假设有一个单位:xx大学(org_id=D001,org_name='xx大学',parent_id='0'),
xx大学下有两个岗位和两个部门,分别是:校长(org_id='G001',org_name='校长',parent_id='D001'),副校长(org_id='G002',org_name='副校长',parent_id='D001')
数学系(org_id='B001',org_name='数学系',parent_id='D001'),物理系(org_id='B002',org_name='物理系',parent_id='D001')
数学系和物理系下面都有几个班级,班级下面就是学生了
表中存储数据格式如下:
org_id org_name parent_id
D001 XX大学 null
G001 校长 D001
G002 副校长 D001
Z001 张三 G001
Z002 李四 G002
Z003 王五 G002
B001 数学系 D001
B002 物理系 D001
B003 数学一班 B001
B004 数学二班 B001
B005 物理一班 B002
Z004 江涛 B003
Z005 赵燕 B003
Z006 陈风 B005
如果我要查询xx大学所有人,要求显示格式为:
XX大学 校长 张三
xx大学 副校长 李四
xx大学 副校长 王五
xx大学 数学系 数学一班 江涛
xx大学 数学系 数学一班 赵燕
xx大学 物理系 物理一班 陈风
也就是说我要查一个人要把他所在的学校、系名、班级、姓名都查出来。
有劳各位大侠帮帮忙。
xx大学下有两个岗位和两个部门,分别是:校长(org_id='G001',org_name='校长',parent_id='D001'),副校长(org_id='G002',org_name='副校长',parent_id='D001')
数学系(org_id='B001',org_name='数学系',parent_id='D001'),物理系(org_id='B002',org_name='物理系',parent_id='D001')
数学系和物理系下面都有几个班级,班级下面就是学生了
表中存储数据格式如下:
org_id org_name parent_id
D001 XX大学 null
G001 校长 D001
G002 副校长 D001
Z001 张三 G001
Z002 李四 G002
Z003 王五 G002
B001 数学系 D001
B002 物理系 D001
B003 数学一班 B001
B004 数学二班 B001
B005 物理一班 B002
Z004 江涛 B003
Z005 赵燕 B003
Z006 陈风 B005
如果我要查询xx大学所有人,要求显示格式为:
XX大学 校长 张三
xx大学 副校长 李四
xx大学 副校长 王五
xx大学 数学系 数学一班 江涛
xx大学 数学系 数学一班 赵燕
xx大学 物理系 物理一班 陈风
也就是说我要查一个人要把他所在的学校、系名、班级、姓名都查出来。
有劳各位大侠帮帮忙。
解决方案 »
- 为什么erwin报错ora00942表或视图不存在。。
- 谁有Oracle与异构数据库导入导出的统一解决方法,给我一份!!!!!!
- 调用Oracle的数据库存储过程时候报了错误,求指教
- 紧急求Oracle sql语句的写法,sqlserver行,oracle不行!在线等!
- 关于ODBC的,我想在其他机器上运行我的应用程序,但是数据源不知道如何设置?
- 求教
- 基础性问题,闲了给解释一下
- connect by问题,请大虾帮忙指点。
- 怎么用SQL语句取得一个视图中某一字段对应于哪个表的哪一字段?
- oracle 8.1.7i (redhat linux 7.3)上,oracle报错。
- 有关敏感数据的问题?
- 50分求一条Oracle的SQL语句
(select org_id oid1,org_name name1,parent_id pid1
from table where parent_id='D001'),
(select org_id oid2,org_name name2,parent_id pid2 from table
where parent_id in (select org_id from table where parent_id='D001')),
(select org_id oid3,org_name name3,parent_id pid3 from table
where parent_id in (select org_id from table
where parent_id in (select org_id from table where parent_id='D001')))
where oid1(+)=pid2 and oid2=pid3(+)
from (select * from org t where t.org_id like 'Z%') t1,
(select *
from org t
where t.parent_id in
(select t.org_id from org t where t.org_id like 'B%')) t2,
(select * from org t where t.org_id like 'B%') t3,
(select * from org t where t.org_id like 'G%') t4,
(select * from org t where t.org_id like 'D%') t5
where t1.parent_id = t2.org_id
and t2.parent_id = t3.org_id
and t3.parent_id = t5.org_id
and t4.parent_id = t5.org_id
union all
select t3.org_name, t2.org_name, t1.org_name, null
from (select * from org t where t.org_id like 'Z%') t1,
(select * from org t where t.org_id like 'G%') t2,
(select * from org t where t.org_id like 'D%') t3
where t1.parent_id = t2.org_id
and t2.parent_id = t3.org_id;