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
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.
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') .
SELECT SUM(grand_total) FROM order
Here is a reference to aggregate functions in MYSQL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With