MySQL变量和的总和

时间:2016-09-03 08:52:58

标签: mysql

我将对totalSale变量求和并将其存储为balanced

这是我的问题:

SELECT
  sum((price * content.owner_percent) / 100) AS totalSale,
  sum(totalSale) as balanced
FROM customer_content
  INNER JOIN content ON content.id = customer.content_id
WHERE content_owner_id = 3;

我该怎么做?!

1 个答案:

答案 0 :(得分:0)

如果我是对的,你想获得平均值(totalSale)的总和。 如果是,你可以这样做:

SELECT sum(src.totalSale) as balanced
FROM (
   SELECT
     sum((price * content.owner_percent) / 100) AS totalSale,
   FROM customer_content
   INNER JOIN content ON content.id = customer.content_id
   WHERE content_owner_id = 3
) AS src