select classId,className,tchrId1,tchrId2,b.tchrName1,c.tchrName2 from class a,(select tchrId,tchrname tchrname1 from tchr where tchrId=a.tchrid1) b,(select tchrId,tchrname tchrname2 from tchr where tchrId=a.tchrid2) c where a.tchrID1=b.tchrID and a.tchId1=c.tchId

解决方案 »

  1.   

    sorry!最后一行,a.tchId1=c.tchId改为a.tchId2=c.tchId
      

  2.   

    CREATE OR REPLACE VIEW TESTVIEW AS
    select a.classId,a.className,a.tchrId1,a.tchrId2,a.tchrName1,b.tchrName2
    from class a,tchr b
    where a.tchrId1=b.tchrId
    如果a.tchrId1和b.tchrId是对应的,就没有错了
      

  3.   

    create or replace view name_view as
    select classId,className,tchrId1,tchrId2,b.tchrName1,c.tchrName2 from class a,(select tchrId,tchrname tchrname1 from tchr where tchrId=a.tchrid1) b,(select tchrId,tchrname tchrname2 from tchr where tchrId=a.tchrid2) c where a.tchrID1=b.tchrID and a.tchId2=c.tchId;
      

  4.   

    SELECT aaa.classId, aaa.className, aaa.tchrId1, 
    aaa.tchrId2, bbb.tchrName AS tchrName1, 
    bbb_1.tchrName AS tchrName2
    FROM aaa ,bbb,bbb bbb_1 
    where aaa.tchrId1 = bbb.tchrId(+) 
    and aaa.tchrId2 = bbb_1.tchrId(+);
      

  5.   

    再来一种:
    select classId,className,tchrId1,tchrId2,
           (select b.tchrname from tchr b where b.tchrid = a.tchrid1) tchrName1,
           (select c.tchrname from tchr c where c.tchrid = a.tchrid2) tchrName2
    from class a
      

  6.   

    create or replace view name_view as
    select classId,className,tchrId1,tchrId2,nvl(b.tchrName1,'null') tchrname2,nvl(c.tchrName2,'null') tchrname2 from class a,(select tchrId,tchrname tchrname1 from tchr where tchrId=a.tchrid1) b,(select tchrId,tchrname tchrname2 from tchr where tchrId=a.tchrid2) c where a.tchrID1=b.tchrID(+) and a.tchId2=c.tchId(+);
      

  7.   

    谢谢各位!  另外(+)是什么意思,是不是允许NULL。
    beckham兄
    select a.class_Id,a.class_Name,a.charge_Id1,a.charge_Id2,b.tchr_Name,c.tchr_Name from class_info a,(select tchr_Id,tchr_Name from tchr_info where tchrId=class_info.charge_Id1) b,(select tchr_Id,tchr_Name from tchr_info where tchr_Id=class_info.charge_Id2) c where 
                                            *
    a.charge_Id1=b.tchr_Id and a.charge_Id2=c.tchr_Id
                                                           
    ERROR 位于第 1 行:
    ORA-00904: 无效列名
    呵呵,不知是哪出错了
    数据库中class表是class_info,tchr表是tchr_info,charge_id引用tchr_id
      

  8.   

    select a.class_Id,a.class_Name,a.charge_Id1,a.charge_Id2,b.tchr_Name,c.tchr_Name from class_info a,(select tchr_Id,tchr_Name from tchr_info where tchrId=a.charge_Id1) b,(select tchr_Id,tchr_Name from tchr_info where tchr_Id=a.charge_Id2) c where a.charge_Id1=b.tchr_Id(+) and a.charge_Id2=c.tchr_Id(+);(+)左连接,把tchr_info 在class_info表没有对应数据就显示为空 
      

  9.   

    to xinpingf(白开心) :
    不要以偏概全啊 :)