Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the sum of a column in all rows mysql

Tags:

mysql

I have a order table and I want to get the total sale till now. This table contain the column grand_total. I want to get the sum of this column from all rows.

   order_id grand_total 
   1         10
   2         20

query should output 30

Thanks

like image 330
Shakti Singh Avatar asked Dec 29 '10 14:12

Shakti Singh


People also ask

How do you get sum all the rows of a column in SQL?

If you need to add a group of numbers in your table you can use the SUM function in SQL. This is the basic syntax: SELECT SUM(column_name) FROM table_name; If you need to arrange the data into groups, then you can use the GROUP BY clause.

How do you sum two columns in MySQL?

Example: MySQL SUM() function using multiple columnsMySQL 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 ('cate_id') .


1 Answers

SELECT SUM(grand_total) FROM order

Here is a reference to aggregate functions in MYSQL.

like image 96
Suirtimed Avatar answered Nov 15 '22 07:11

Suirtimed