php - SQL totals by percentages calculation -


i want sql query go

shop    regio    target1    sold1    target2    sold2  shop1   regioa   6          3        10         5 shop2   regioa   4          2        4          2 shop3   regiob   6          0        3          0 shop4   regioc   9          9        8          8 shop5   regiob   8          4        2          1 

to

regioc      100% regioa       50% regiob       25% 

(nevermind numbers, made these up)

i tried using didn't work:

select regio, sum((sold2/target1)+(sold2/target2)) total   `winkels` group `regio` order total desc  

any ideas how make right?

this should work. trying add percentages together, instead of dividing totals.

select regio, 100*sum(sold1+sold2)/sum(target1 +target2) total   `winkels` group `regio` order total desc  

Comments