解决方案 »

  1.   

    select  a.xm, a.xh,a.gzdw,b.khnd,b.khdc  from  tbMain a,tbKh b where a.xh=b.xh        
      

  2.   

    select  a.xm, a.xh,a.gzdw,b.khnd,if(b.khdc =null, 'NULL',b.khdc)  AS  khdc  from  tbMain a,tbKh b where a.xh=b.xh 
      

  3.   

    SELECT TBMAIN.XM, TBMAIN.XH, TBMAIN.GZDW, TBKH.KHND, NVL(TBKH.KHDC, 'NUL')
      FROM TBMAIN, TBKH
     WHERE TBMAIN.XH = TBKH.XH(+)
      

  4.   


    create table tbMain
    (xm varchar(10),xh varchar(10),gzdw varchar(10))insert into tbMain
     select '张三','A001','市招商局' union all
     select '李四','A002','市招商局' union all
     select '王五','B001','市教育局' union all
     select '张兵','B002','市教育局'create table tbKh
    (xh varchar(10),khnd varchar(10),khdc varchar(10))insert into tbKh
     select 'A001','2012','优秀' union all
     select 'A002','2012','合格' union all
     select 'A001','2013','优秀' union all
     select 'B001','2012','优秀' union all
     select 'B002','2012','合格' union all
     select 'B001','2013','优秀' union all
     select 'B002','2013','合格'
    select a.xm,a.xh,a.gzdw,b.khnd,b.khdc
    from tbMain a
    left join tbKh b on a.xh=b.xh and khnd='2013'
    where a.gzdw='市招商局'/*
    xm         xh         gzdw       khnd       khdc
    ---------- ---------- ---------- ---------- ----------
    张三         A001       市招商局       2013       优秀
    李四         A002       市招商局       NULL       NULL(2 row(s) affected)
    */