行的多列值的总和

时间:2018-05-28 08:54:55

标签: mysql database

我希望每个学生单独获得sub_1,sub_2,sub_3的总和

enter image description here

2 个答案:

答案 0 :(得分:3)

我认为这是mysql:

select s_f_name,s_l_name,SUM(sub_1 + sub_2 + sub_3) as total from tablename group by s_f_name,s_l_name

答案 1 :(得分:2)

试试这个

SELECT s_id, s_f_name, s_l_name, s_roll_no, s_class, SUM(sub_1 + sub_2 + sub_3) AS sum FROM <table name> GROUP BY s_id

输出:

s_id   s_f_name   s_l_name   s_roll_no   s_class   sum
1      Mridul     Kumar      1           1         42
2      Manish     Paul       2           1         48
3      Sritima    Baneriee   3           1         57