我有一个查询,它有几个相同的和函数。运行单独的求和查询然后将其绑定到我的原始查询作为值以加快它是否更有效?
我当前的查询
$dbquery = $dbh->prepare("
SELECT amount - (Select SUM(amountused) from tblamountused) as amountleft
FROM tblamount
WHERE amount - (Select SUM(amountused) from tblamountused) > 0
");
答案 0 :(得分:3)
也许是这样的:
SELECT amount - (Select SUM(amountused) from tblamountused) as amountleft
FROM tblamount
HAVING amountleft > 0