答案 0 :(得分:0)
每位学生的平均成绩:
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
每所学校的平均分数
{{1}}
答案 1 :(得分:0)
Hive应自动忽略报告here的聚合上的NULL
值。
为了便于阅读,我建议使用COALESCE
代替IF IS NULL
语句,例如:COALESCE(Math,0) as Math