日期:2014-05-17 浏览次数:20446 次
SELECT A.StudentName,B.ClassName FROM C INNER JOIN A ON A.StudentID=C.StudentID INNER JOIN B ON B.ClassID= C.ClassID WHERE A.StudentName='李四'
SELECT StudentID,ClassID INTO #Temp FROM C WHERE StudentID IN (SELECT StudentID FROM C GROUP BY StudentID HAVING COUNT(1) = 1) SELECT A.StudentName FROM #Temp D INNER JOIN A ON A.StudentID=D.StudentID INNER JOIN B ON B.ClassID= D.ClassID WHERE B.ClassName='计算机原理' DROP TABLE #Temp
SELECT StudentID,Score INTO #Temp1 FROM C WHERE Score < 60 SELECT StudentID INTO #Temp2 FROM #Temp1 GROUP BY StudentID HAVING COUNT(1) >= 2 SELECT A.StudentName,B.ClassName,C.Score FROM C INNER JOIN A ON A.StudentID=C.StudentID INNER JOIN B ON B.ClassID= C.ClassID WHERE C.StudentID IN (SELECT StudentID FROM #Temp2) ORDER BY C.StudentID DROP TABLE #Temp1,#Temp2
-方法2可这样写 select * from B inner join C as D on B.ClassID=D.ClassID inner join A on A.StudentID=D.StudentID where b.ClassName='计算机原理' and not exists(select 1 from C where StudentID=D.StudentID and ClassID<>D.ClassID) 方法3 select * from B inner join C as D on B.ClassID=D.ClassID inner join A on A.StudentID=D.StudentID where exists(select 1 from C where StudentID=A.StudentID and Score<60 having count(distinct ClassID)>1)
------解决方案--------------------