0

我想要一个 SQL 查询

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

regioC      100%
regioA       50%
regioB       25%

(别管数字,我只是编的)

我尝试使用它,但它没有用:

SELECT regio, SUM((sold2/target1)+(sold2/target2)) AS total 
FROM  `winkels` GROUP BY `regio` ORDER BY total DESC 

任何想法如何使它正确?

4

1 回答 1

3

这应该有效。您试图将百分比相加,而不是除以总数。

SELECT regio, 100*SUM(sold1+sold2)/sum(target1 +target2) AS total 
FROM  `winkels` GROUP BY `regio` ORDER BY total DESC 
于 2013-07-11T12:43:22.723 回答