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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -