表 A
id   sname  
1     A
2     B
3     C表 Bid  class
 1   N.1
 2   N.2
 
问题来了:需要如下结果集id sname  class
1  A       N.1
2  B       N.2
3  C       no class在线=哦 请用标准Sql

解决方案 »

  1.   


    select a.id,a.sname,nvl(b.class,'no class') from a,b where a.id=b.id(+);
      

  2.   

    select id,sname,nvl(class,'no class') class from (select a.id ,a.sname,b.class
      from a left join b on a.id=b.id) 
      

  3.   

    跟2楼的差不多,顺便解释一下。+在右边的是左连接的意思。就是left join
      

  4.   

    nvl 是oracle的东东吧 能不能用标准的sql    呵呵
      

  5.   

    2楼正解
    这样写也行
    select t1.id, t1.sname, decode(t2.class, null, 'no class', t2.class)
      from table1 t1, table2 t2
     where t1.id = t2.id(+)
      

  6.   

    select a.id,a.sname,case when b.class is null then 'no class' else b.class end class from  a left join b on a.id=b.id
    这个总可以了吧。
      

  7.   

     else b.class end class from  from 之前的 class 是什么意思?