如何显示平均GPA的百分比> 3.5?

时间:2016-12-06 08:06:02

标签: mysql sql

我的查询显示了学生的GPA,但我不确定如何显示拥有GPA的学生百分比> 3.5。

SELECT avg(Grade) as GPA, studentID from tblTranscript
GROUP BY studentID

3 个答案:

答案 0 :(得分:0)

简单地说,having是向导:

SELECT avg(Grade) as GPA, studentID from tblTranscript
GROUP BY studentID
HAVING avg(Grade) > 3.5

答案 1 :(得分:0)

希望这有帮助。

SELECT avg(Grade) as GPA, studentID from tblTranscript
GROUP BY studentID HAVING avg(Grade)>3.5; 

答案 2 :(得分:0)

这有效:

SELECT  
    (SELECT COUNT(*) FROM (
        SELECT * FROM (
            SELECT AVG(Grade) as GPA, studentID 
            FROM tblTranscript
            GROUP BY studentID
        ) AS a 
        WHERE a.GPA > 3.5
    ) as d) 
    /
    (SELECT COUNT(*) FROM (
        SELECT * 
        FROM tblTranscript 
        GROUP BY studentID
    ) as e)
AS percentage

我的tblTranscript位于:

CREATE TABLE `tbltranscript` (
  `id` int(11) NOT NULL,
  `studentID` int(11) DEFAULT NULL,
  `Grade` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1