【发布时间】:2019-04-16 01:47:35
【问题描述】:
这是我的查询
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 condation SUM(gpa)/count(subject_name
不工作subject_type=1,SUM(gpa)-2/count(subject_name)
我的桌子
结果:gpa = 5+8+4+6
= 23
但是 subject_type = 1 so ,minus -2(不起作用)
= 21 (Not work)
最终 Gpa = 21/count(subject_name)
【问题讨论】:
-
你为什么要除以
count(subject_name)? -
总科目
like = 7 or 9 ... -
所以你要取平均值?
-
是的,我尝试
(total_gpa)/total_subject如果有任何extra subject然后minus (-2)形成总数gpa -
那么,如果任何主题有
subject_type=1,你是减2还是每一个主题有subject_type=1减2?
标签: php mysql codeigniter mysqli