1.学校所有成员表(包括学生和老师) member(表名)
unit_type:1表示学生,无的表示老师
id name unit_type status
1 李欣 1 在校
2 张娜
3 杨帆 1 毕业
4 高希
5 秦风 1 在校
6 陈瑜 1 在校
7 伍峰 1 毕业
8 刘玉
9 谢娜
10 晨星
status:状态,不必了解具体意义
说明:只有学生的状态在此表显示,老师的状态在另教师级别显示2.教师级别表(me_id字段对应member表中的ID字段)
ID me_id state
1 2 校长
2 4 教员
3 8 教员
4 9 教授
5 10 教授结果:希望通过对查询得到以下结果
编号 姓名 目前状态
1 李欣 在校
2 张娜 校长
3 杨帆 毕业
4 高希 教员
5 秦风 在校
6 陈瑜 在校
7 伍峰 毕业
8 刘玉 教员
9 谢娜 教授
10 晨星 教授我要实现的功能类似,请高手帮个忙,希望通过sql语句得到以下结果 自己写的还是有差距

解决方案 »

  1.   

    seelct aa.*
    from
    (
    select a.id 编号,a.name 姓名,a.status 目前状态
    from member a
    where a.unit_type=1
    union all
    select a.id.a.name,b.state
    from member a,教师级别表b
    where a.unit_type is null and a.id=b.me_id) aa
    order by 1
      

  2.   


    select a.id,a.name,nvl(b.state,a.status) from  member a, 教师级别表 b where a.id=b.me_id(+)
      

  3.   

    二楼的,为什么只写
    select a.id 编号,a.name 姓名,a.status 目前状态 
    from member a 
    where a.unit_type=1 
    union all 
    select a.id.a.name,b.state 
    from member a,教师级别表b 
    where a.unit_type is null and a.id=b.me_id
    不可以啊?
    为什么要写外面的那一层?
    在此先谢了哈