日期:2014-05-18 浏览次数:20562 次
Select a.id_student,ISNULL(b.score,0) AS score From Student a Left Outer Join score b on a.id_student=b.id_student Where[color=#FF0000] b.id_student Is Null [/color]or b.score<60
------解决方案--------------------
IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'Student')
BEGIN
DROP TABLE Student
END
GO
CREATE TABLE Student
(
id_student INT,
grade INT
)
GO
IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'score')
BEGIN
DROP TABLE score
END
GO
CREATE TABLE score
(
id_score INT,
id_student INT,
score INT
)
GO
INSERT INTO Student
SELECT 1,1 UNION
SELECT 2,1 UNION
SELECT 3,1 UNION
SELECT 4,1
INSERT INTO score
SELECT 1,1,70 UNION
SELECT 2,3,57 UNION
SELECT 3,4,10
SELECT A.id_student,score
FROM Student AS A LEFT OUTER JOIN score AS B ON A.id_student = B.id_student
WHERE ISNULL(score,0) < 60
id_student score
2 NULL
3 57
4 10