Mysql - 查询中的多个Sum函数

时间:2013-11-12 15:02:47

标签: mysql pdo

我有一个查询,它有几个相同的和函数。运行单独的求和查询然后将其绑定到我的原始查询作为值以加快它是否更有效?

我当前的查询

$dbquery = $dbh->prepare("
SELECT amount - (Select SUM(amountused) from tblamountused) as amountleft
FROM tblamount
WHERE amount - (Select SUM(amountused) from tblamountused) > 0
");

1 个答案:

答案 0 :(得分:3)

也许是这样的:

SELECT amount - (Select SUM(amountused) from tblamountused) as amountleft
FROM tblamount
HAVING amountleft > 0