SELECT student, (SUM(mark1)+SUM(mark2)+SUM(mark3)....+SUM(markn)) AS Total
 FROM your_table
 GROUP BY student
Answer from Maulik patel on Stack Overflow
๐ŸŒ
w3resource
w3resource.com โ€บ mysql โ€บ aggregate-functions-and-grouping โ€บ aggregate-functions-and-grouping-sum().php
MySQL SUM() function
March 2, 2026 - MySQL SUM() function retrieves the sum value of an expression which is made up of more than one columns. The above MySQL statement returns the sum of multiplication of 'receive_qty' and 'purch_price' from purchase table for each group of category ...
๐ŸŒ
Plus2Net
plus2net.com โ€บ sql_tutorial โ€บ sql_sum-multiple.php
Sum sql for data in multiple columns and across rows with Total & Percentage
February 5, 2000 - SELECT SUM( column_name ) FROM table_name We have seen how the sum function is used to get the total value of a column in a MySQL table. Now we will learn how to get the query for sum in multiple columns and for each record of a table. For a better understanding we will change our student table ...
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ mysql โ€บ mysql sum multiple columns
How to Get Sum of Multiple Columns in MySQL | Delft Stack
March 11, 2025 - Learn how to sum multiple columns in MySQL with our comprehensive guide. Explore various methods, including using the SUM function, conditional logic, and grouping results. Enhance your data analysis skills with practical examples and clear explanations. Perfect for beginners and experienced ...
๐ŸŒ
YouTube
youtube.com โ€บ programming for everybody
MySQL Tutorial for Beginners -Sum Multiple columns and Multiple Rows to Get total sum in phpMyAdmin - YouTube
MySQL Tutorial for Beginners - Sum Multiple columns and Multiple Rows to Get total sum in phpMyAdminVideos mysqlSubscribe to my channel to find everyday new ...
Published: September 17, 2023
Views: 946
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ sql queries โ€บ how to sum two columns in an sql query?
How to Sum Two Columns in an SQL Query? Baeldung on SQL
May 16, 2025 - The total_sales column is for the total magazine sales across all publishers; its value stays the same for each row of data in the result set. ... SELECT publisher_id,magazine_name,q1sales+q2sales AS magazine_sales, SUM(q1sales+q2sales) OVER(PARTITION BY publisher_id) AS publisher_sales, SUM(q1sales+q2sales) OVER() AS total_sales FROM magazine WINDOW w AS (PARTITION BY publisher_id ORDER BY publisher_id);
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ select-multiple-sums-with-mysql-query-and-display-them-in-separate-columns
Select multiple sums with MySQL query and display them in separate columns?
The query to get a separate column with multiple sum: mysql> select -> SUM(CASE WHEN PlayerName='Maxwell' THEN PlayerScore END) AS 'MAXWELL TOTAL SCORE', -> SUM(CASE WHEN PlayerName='Ricky' THEN PlayerScore END) AS 'RICKY TOTAL SCORE', -> SUM(CASE WHEN PlayerName='David' THEN PlayerScore END) AS 'DAVID TOTAL SCORE' -> from selectMultipleSumDemo;
Find elsewhere
๐ŸŒ
MySQL
forums.mysql.com โ€บ read.php
MySQL :: The SUM of Multiple Columns
October 17, 2007 - I know that this will sum 2 columns: SELECT SUM(billing.space_cost) + SUM(billing.pub_box) FROM billing and thought that this would do more, but it does not seem to work: SELECT (SUM(billing.space_cost) + SUM(billing.pub_box) + SUM(billing.messenger)) FROM billing
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ func_mysql_sum.asp
MySQL SUM() Function
String Functions: ASCII CHAR_LENGTH CHARACTER_LENGTH CONCAT CONCAT_WS FIELD FIND_IN_SET FORMAT INSERT INSTR LCASE LEFT LENGTH LOCATE LOWER LPAD LTRIM MID POSITION REPEAT REPLACE REVERSE RIGHT RPAD RTRIM SPACE STRCMP SUBSTR SUBSTRING SUBSTRING_INDEX TRIM UCASE UPPER Numeric Functions: ABS ACOS ASIN ATAN ATAN2 AVG CEIL CEILING COS COT COUNT DEGREES DIV EXP FLOOR GREATEST LEAST LN LOG LOG10 LOG2 MAX MIN MOD PI POW POWER RADIANS RAND ROUND SIGN SIN SQRT SUM TAN TRUNCATE Date Functions: ADDDATE ADDTIME CURDATE CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP CURTIME DATE DATEDIFF DATE_ADD DATE_FORMAT DA
๐ŸŒ
Quora
quora.com โ€บ How-do-I-sum-two-columns-in-SQL
How to sum two columns in SQL - Quora
Answer (1 of 8): Simply column1 + column2 if both columns are not nullable Otherwise would require converting nulls to default numeric value like 0 using functiobs like COALESCE, NVL etc depending on the producf you use For example in SQLServer it is COALESCE and you use like SELECT COALESCE(C...
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ mysql โ€บ mysql-sum
MySQL SUM() Function: Usage & Examples
This example uses `SUM()` along with `GROUP BY` to calculate the total amount spent by each customer. Use Aliases. Use aliases (`AS`) for clear and understandable result column names.
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ data science โ€บ data science tutorials โ€บ mysql tutorial โ€บ mysql sum()
MySQL sum() | Complete Guide to MySQL sum() with Query Examples
June 6, 2023 - Since the SUM() is an aggregate function, it works on multiple table rows or a table column to find the sum result to return only a value. Let us evaluate the MySQL SUM() to show the sum working with the table columns and rows to get the result total set.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-can-i-sum-columns-across-multiple-tables-in-mysql
How can I sum columns across multiple tables in MySQL?
July 30, 2019 - To sum columns across multiple tables, use UNION ALL. To understand the concept, let us create first table. The query to create first table is as follows ยท mysql> create table Products1 -> ( -> ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ProductName varchar(20), -> ProductPrice int ...
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ mysql sum
MySQL SUM() Function - Scaler Topics
May 18, 2023 - If the input column contains any non-numeric data, you will receive an error message indicating that the argument is not valid. ... The MySQL SUM() function works by adding up all the values from the input column. It adds up everything by iterating over each row in the given table and adding ...
Top answer
1 of 2
1

NOTE: I have no idea what 'GATE Mock Test Paper' is, or if that's supposed to have a bearing on the answer, so fwiw ...

As others have pointed out, technically all of the answers could be true ... though this will depend on the RDBMS (ie, flavor of SQL) as well as any configs/settings.


If the intention is to pick answers that are ANSI compliant, then I'd say 'III' is the correct answer since all non-aggregates should be part of the group by. Then again, if you start looking at some of the nitty-gritty ANSI details you'll find this requirement can sometimes be relaxed.

As you'll find out, most RDBMS products don't enforce such a strict standard: all non-aggregates being a member of the group by clause


As Michael Kutz has mentioned, without 'A' and/or 'B' in the select/projection list, answers 'I' and 'II' will provide some confusing answers. [And if you ever find yourself working in a real world RDBMS environment you'll find developers writing these types of queries all the time, but then not being able to describe what it is they're asking for let alone being able to explain the results they end up with.]

Again, answer 'III' is the only one I'd say can be clearly explained ... what I'm looking for ... the results I end up with.

2 of 2
0

Answer

All of them are valid. However, I and II are logical nonsense.

Expected Results

For every A,B combination, you will get 1 row irregardless of what columns/aggregates are listed in the SELECT clause. If you have 100 distinct combinations of A,B, I expect your result to show 100 rows for I,II, and III.

Logic

Answer I will show a series of values. You will have no idea which values are for which A,B combination because A and B are not part of your SELECT statement. Because you don't have an ORDER BY clause, you can make no assumptions about which row matches to which combination of A,B.

Answer II will show a series of values for each distinct value of A. You will have no idea which values are for which A,B combination because B is not part of your SELECT statement. Because you don't have an ORDER BY clause, you can make no assumptions about which row matches to which combination of A,B.

Answer III will show a series of values for each distinct combination of A,B.

Conclusion

From a syntax stand point, they are all valid.

From a logical stand point, only III is valid.