关于两张表的合成 急!!
要怎么写才可以把第一张图片上的Firvolun和Secvolun 按照图片二中Hid对应的Hname 显示出来?
------解决方案--------------------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
------解决方案--------------------Students没有值的话,你只能看Student的信息, Hospital的信息没有办法关联.
那前面的语句中的inner join用left outer join代替就可以
------解决方案--------------------SQL code
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