select (select 工号,姓名 from 表A where 工号 = 'A01'),
(select 工号,姓名 from 表A,表B 
where 表B.工号 = 'A01' and 表A.工号=表B.上级员工工号),
(select 工号,姓名 from 表A,表B 
where 表B.工号 = 'A01' and 表A.工号=表B.下级员工工号)

解决方案 »

  1.   

    我的意思是
    表A是基本表,显示员工工号和姓名
    表B应该叫上下级关系表,存放一个员工的工号,所属上级的工号,所属下级的工号
    我现在要求是显示
    把一个员工工的工号和姓名,和他所属的上下级的工号和姓名同时显示出来,(其中,上下级工号和表A里的员工工号是对应的)
    结果显示的格式
    工号 姓名
    111  a      (本人)
    222  b
      

  2.   

    我的意思是
    表A是基本表,显示员工工号和姓名
    表B应该叫上下级关系表,存放一个员工的工号,所属上级的工号,所属下级的工号
    我现在要求是显示
    把一个员工工的工号和姓名,和他所属的上下级的工号和姓名同时显示出来,(其中,上下级工号和表A里的员工工号是对应的)
    结果显示的格式
    -----------
    工号 姓名
    111  a      (本人)
    222  b       (上级)
    333  C       (下级)
      

  3.   

    修改一下
    select 
    temp1.工号,temp1.姓名,
    temp2.工号 as 上级员工工号,temp2.姓名 as 上级员工姓名,
    temp3.工号 as 下级员工工号,temp3.姓名 as 下级员工姓名
    from
    (select 工号,姓名 from 表A where 工号 = 'A01') temp1,
    (select 表A.工号,表A.姓名 from 表A,表B 
    where 表B.工号 = 'A01' and 表A.工号=表B.上级员工工号) temp2,
    (select 表A.工号,表A.姓名 from 表A,表B 
    where 表B.工号 = 'A01' and 表A.工号=表B.下级员工工号) temp3
      

  4.   

    按你的意思重写语句:
    select 表A.* from 表A,表B
    where 表A.工号 = 'A01'
    or
    (表A.工号 = 表B.上级员工工号)
    or 
    (表A.工号 = 表B.下级员工工号)
      

  5.   

    楼上的起码你的输出格式就没处理啊
    你怎么确定你的显示是工号 姓名
    111  a      (本人)
    222  b       (上级)
    333  C       (下级)呢?保不准就成了工号 姓名
    222  b       (上级)
    111  a       (本人)
    333  C       (下级)
      

  6.   

    在更改:
    select 表A.* from 表A,表B
    where 表A.工号 = 'A01'
    union
    select 表A.* from 表A,表B
    表A.工号 = 表B.上级员工工号
    union
    select 表A.* from 表A,表B
    表A.工号 = 表B.下级员工工号
      

  7.   

    select a.工号,a.姓名,b.上级员工工号, 上级员工姓名=c.姓名,b.下级员工工号,下级员工姓名=d.姓名 from t1 a left join t2 b on a.工号=b.工号
    left join t1 c on b.上级员工工号=c.工号 
    left join t1 d on b.下级员工工号=d.工号
      

  8.   

    select 工号,姓名 from A where A.工号=B.工号 工号='A01' or 工号=(select 上级的工号 from B where 工号='A01') or 工号=(select 下级的工号 from B where 工号='A01')
      

  9.   

    这样你试试可以吗
    select 表A.* from 表A
    where 表A.工号 = 'A01'
    union
    select 表A.* from 表A
    where 
    表A.工号 = (select 表B.上级员工工号 from B where B.工号= 'A01')
    union
    select 表A.* from 表A
    where
    表A.工号 = (select 表B.下级员工工号 from B where B.工号= 'A01')
      

  10.   

    上在的不对
    这个应该差不多
    select 工号,姓名 from A where 工号='A01' or 工号=(select 上级的工号 from B where 工号='A01') or 工号=(select 下级的工号 from B where 工号='A01')