我想这个苯方法应该可以吧:
select
(select ID from students where ID=a.ID) as ID,
(select name from students where ID=a.ID) as name,
(select sex from students where ID=a.ID) as sex,
(select birth from students where ID)=a.ID as birth,
a.subject,a.score from teachers a
上面寫錯了
select identity(int,1,1) as nowid,* into #temp from teachers
select a.ID,a.name, a.sex,a.birth,b.ID,b.subject,b.score from students a left join (select ID,stuId,subject,score from teachers where nowid in (select
min(nowid) from #temp group by stuId)) b on a.ID=b.stuID
select identity(int,1,1) as nowid,* into #temp from teachers
select a.ID,a.name, a.sex,a.birth,b.ID,b.subject,b.score from students a left join (select ID,stuId,subject,score from teachers where nowid in (select
min(nowid) from teachers group by stuId)) b on a.ID=b.stuID
Select a.*,b.subject,c.score from students a
Left Join
(Select stuID,min(id) as id from teachers group by stuID) b on a.id = b.stuID
left join teachers c on b.id = c.id
1.select s.*,stuid,subject ,score from students s left join teachers t on s.[id]=t.[id]
2,select t.stuid, name,sex,birth from students s left join on teachers t on s.id=t.id