Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do sum of sum in mysql query

Tags:

sql

mysql

SELECT a.id AS supplier, sum( processed_weight ) AS total_qty
FROM supplier_inward a
INNER JOIN warehouseb ON a.id = b.supplier
WHERE a.master_product_id = '38'
GROUP BY b.supplier

output present

supplier    total_qty
12046      475.00
12482      99.00

output needed

total_qty
574.00

here i need the sum(total_qty) in this query? how to achieve this

like image 575
Ghostman Avatar asked Jan 02 '12 11:01

Ghostman


People also ask

How do I sum a query in MySQL?

MySQL SUM() FunctionThe SUM() function calculates the sum of a set of values. Note: NULL values are ignored.

How do you sum sums in SQL?

AVG() SyntaxThe SUM() function returns the total sum of a numeric column.

How can I sum two columns in MySQL?

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 ('cate_id') .

How do I sum a group in MySQL?

SUM() function with group by MySQL SUM() function retrieves the sum value of an expression which has undergone a grouping operation by GROUP BY clause.


1 Answers

how about this:

SELECT SUM(iQuery.total_qty) as iTotal
FROM
    (SELECT a.id AS supplier, sum( processed_weight ) AS total_qty
    FROM supplier_inward a
    INNER JOIN warehouseb ON a.id = b.supplier
    WHERE a.master_product_id = '38'
    GROUP BY b.supplier) as iQuery
like image 81
John Woo Avatar answered Sep 20 '22 07:09

John Woo