select school,SL_No,Name,Math,Phy,Chem,(if(Math is NULL,0,Math)+if(Phy is NULL,0,Phy)+if(Chem is NULL,0,Chem))/3 as avg_marks from my_table
各校平均分
select school,avg(avg_marks) from (select school,SL_No,Name,Math,Phy,Chem,(if(Math is NULL,0,Math)+if(Phy is NULL,0,Phy)+if(Chem is NULL,0,Chem))/3 as avg_marks from my_table
) temp group by school
2条答案
按热度按时间bbmckpt71#
配置单元应自动忽略
NULL
此处报告的骨料值。为了可读性,我建议使用
COALESCE
而不是IF IS NULL
陈述如下:COALESCE(Math,0) as Math
vmdwslir2#
每个学生的平均成绩:
各校平均分