要怎么写才可以把第一张图片上的Firvolun和Secvolun 按照图片二中Hid对应的Hname 显示出来?

解决方案 »

  1.   

    第一张表叫Volunteer 第二张表叫Hospital
      

  2.   

    select Sno, Firvolun, H1.Hname, Secvolun, H2.Hname from Volunteer
    inner join Hospital H1 on H1.Hid = Volunteer.Firvolun
    inner join Hospital H2 on H2.Hid = Volunteer.Firvolun
      

  3.   

    如果表Students中的Firvolun和Secvolun没有值,那怎么写让他们也一起输出来啊?
      

  4.   

    Students没有值的话,你只能看Student的信息, Hospital的信息没有办法关联.
    那前面的语句中的inner join用left outer join代替就可以
      

  5.   

    select Hname  from   Volunteer H1,Hospital H2  where  (H1.Firvolun=H2.Hid or H1.Secvolun=H2.Hid) 
    union 
    select Hname  from   Volunteer where Firvolun   is   NULL  or  Secvolun  is  NULL