MySql calculation in aggregate -
i have created working statement calculating "c" using formula c=a/b*1000000.
this works expected , c column calculated correctly:
select chemicals.region region, chemicals.totalt `a`, `area`.`m2` `b`, ((chemicals.totalt / `area`.`m2`) * 1000000) c (chemicals join `area` on chemicals.branch = `area`.branch)
now need use same formula in aggregated report, tried this:
select chemicals.region region, sum(chemicals.totalt) `a`, sum(`area`.`m2`) `b`, sum( ((chemicals.totalt / `area`.`m2`) * 1000000)) c (chemicals join `area` on chemicals.branch = `area`.branch) group region
but value of "c" not calculated correctly.
i sure there way right, adding sum sum function "c" calculation not correct. (the columns , b correct, way).
thanks help!
as figured out in comments, following solution work:
((sum(chemicals.totalt) / sum(area.m2)) * 1000000) c
Comments
Post a Comment