这是我的问题
CREATE VIEW marksheet as
SELECT name as name, student_id as student_id,
roll as roll, class as class,exam_year as exam_year,
subject_name as subject, exam_type as exam_type,
sum(full_mark) as full_mark, sum(getmark) as getmark,
department as department,
IF(SUM(IF(gpa='f' OR gpa='F',-9999,gpa))>=0,
CAST(IF(subject_type=1,SUM(gpa)-2/count(subject_name),SUM(gpa)/count(subject_name))
AS CHAR), 'F') as total_gpa
FROM mark
GROUP by roll, class, exam_type
不起作用 IF(subject_type=1,SUM(gpa)-2/count(subject_name),SUM(gpa)/count(subject_name))
每次只工作 else
条件 SUM(gpa)/count(subject_name
不起作用 subject_type=1,SUM(gpa)-2/count(subject_name)
我的table
结果:gpa=5+8+4+6
= 23
但主题类型=1 so ,minus -2
(不工作)
= 21 (Not work)
最终gpa=21/计数(受试者姓名)
1条答案
按热度按时间hfwmuf9z1#
如果只能有一个额外的主题(即
subject_type=1
)其他科目都有subject_type=0
,您可以使用MAX(subject_type)
确定学生是否选修了额外的科目。这个查询应该满足您的需要(注意,您还需要()
周围SUM(gpa)-2
):我在sqlfiddle创建了一个简化的演示。