mysql—一行(两列的平均值)和同一行(另一列的值)的和

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


我写了一个查询,但它显示错误。我想得到 mid_1_english 以及 mid_2_english 然后把平均值加上 semester_final_english .

select s_roll_no, s_f_name, s_l_name, s_class, 
           SUM(mid_1_english + mid_2_english)/2 as mid_english, 
           SUM(mid_1_mathematics + mid_2_mathematics)/2 as mid_mathematics, 
           SUM(mid_english + semester_final_english) as total_english, 
           SUM(mid_mathematics + semester_final_mathematics) as total_mathematics 
from elaborate_result 
group by s_f_name, s_l_name;
LIMIT 0, 50000

错误代码:1054。“字段列表”0.000秒中的未知列“mid\u english”

cygmwpex

cygmwpex1#

当你这样做的时候

Select SUM(mid_1_english + mid_2_english)/2 as mid_english

它不会创建一个新的列mid\u english。因此不能将其用作同一查询中的列。
所以你需要的可能是这样的

select s_roll_no, s_f_name, s_l_name, s_class, 
       SUM(mid_1_english + mid_2_english)/2 as mid_english, 
       SUM(mid_1_mathematics + mid_2_mathematics)/2 as mid_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 
    from elaborate_result 
  group by s_f_name, s_l_name;
 LIMIT 0, 50000

相关问题