Check out example codes for "mysql select inside sum". It will help you in understanding the concepts better.

Code Example 1

SELECT x.prod_name
     , SUM(x.total)
  FROM ( SELECT bp.prod_name
              , ( SELECT SUM( wh.quantity ) * bp.weight 
                    FROM bus_warehouse_entries wh
                   WHERE bp.prod_code = wh.org_product_code ) AS total
       FROM bus_products bp ) x
 GROUP BY x.prod_name

Learn ReactJs, React Native from akashmittal.com