1

我正在使用以下查询:

4

1 回答 1

2

由于未提供示例数据,因此未对以下查询进行全面测试。

SELECT  d.LecturerID, d.Name,
        c.CourseID, c.CourseName,
        a.Semester,
        a.percentageOfStudent
FROM
        (
            SELECT  CourseID,
                    Semester,
                    SUM(CASE WHEN grade >= 6 THEN 1 ELSE 0 END) * 1.0 / COUNT(*) * 100.0 percentageOfStudent
            FROM    Exam
            GROUP   BY CourseID, Semester
            HAVING  SUM(CASE WHEN grade >= 6 THEN 1 ELSE 0 END) * 1.0 / COUNT(*) * 100.0 < 50
        ) a 
        INNER JOIN Lecture b
            ON  a.CourseID = b.CourseID AND
                a.Semester = b.Semester
        INNER JOIN Course c
            ON  b.CourseID = c.CourseID
        INNER JOIN  Lecturer d
            ON b.LecturerID = d.LecturerID
于 2013-03-11T23:06:10.060 回答