为什么sum()函数在这种情况下没有给出确切的值?

h9a6wy2h  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(537)

select s_id, s_f_name, s_l_name, s_roll_no, s_class, 
       SUM(mid_1_english + mid_2_english)/2 as mid_english, 
       SUM(mid_1_mathematics + mid_2_mathematics)/2 as mid_mathematics,
       semester_final_english,
       semester_final_mathematics,
       SUM((mid_1_english + mid_2_english)/2 + semester_final_english) as total_english, 
       SUM((mid_1_mathematics + mid_2_mathematics)/2 + semester_final_mathematics) as total_mathematics,
       SUM((mid_1_mathematics + mid_2_mathematics)/2 + (mid_1_english + mid_2_english)/2 + semester_final_mathematics + semester_final_mathematics) as total
from elaborate_term_result_sheet 
group by s_f_name, s_l_name
order by s_roll_no;

在运行这个创建的查询之后,它确实显示输出,但是值有点波动

中英文+中英文=中英文
数学+数学=数学
中英文+期末英文=总英文
期中数学+期末数学=总数学
合计=英语合计+数学合计

ktca8awb

ktca8awb1#

select s_id, s_f_name, s_l_name, s_roll_no, s_class, 
   SUM(mid_1_english + mid_2_english)/2 as mid_english, 
   SUM(mid_1_mathematics + mid_2_mathematics)/2 as mid_mathematics,
   semester_final_english,
   semester_final_mathematics,
   SUM((mid_1_english + mid_2_english)/2 + semester_final_english) as total_english, 
   SUM((mid_1_mathematics + mid_2_mathematics)/2 + semester_final_mathematics) as total_mathematics,
   SUM((mid_1_english + mid_2_english)/2 + semester_final_english + (mid_1_mathematics + mid_2_mathematics)/2 + semester_final_mathematics) as total from result_sheet_1 group by s_f_name, s_l_name order by s_roll_no;

给出正确输出的唯一变化是

SUM((mid_1_english + mid_2_english)/2 + semester_final_english + (mid_1_mathematics + mid_2_mathematics)/2 + semester_final_mathematics) as total

此查询输出的快照

相关问题