sum of a row's multiple column's value

时间:2022-05-26 07:41:20

I want to get the sum of sub_1, sub_2, sub_3 for every student individually

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

sum of a row's multiple column's value

2 个解决方案

#1


3  

I assume this is mysql:

我假设这是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

#2


2  

Try this

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

Output :

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

#1


3  

I assume this is mysql:

我假设这是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

#2


2  

Try this

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

Output :

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