我有这个查询
$my_taxes = mysql_fetch_array(mysql_query("SELECT SUM(FEE) FROM clients WHERE EMAIL = '$EMAIL'"));
另外,我有一个名为付款的辅助表,其中列(PAID)带有2个ENUM选项(待定和准备好)
我需要获取一个变量,该变量通过来自表客户端的特定电子邮件来计算总费用,但仅当辅助表中的PAID列值被选为待定时才会这样。
这是我到现在为止所尝试的
$my_taxes = mysql_fetch_array(mysql_query("SELECT SUM(FEE) FROM clients WHERE EMAIL = '$EMAIL' UNION ALL SELECT PAID FROM payments WHERE EMAIL = '$EMAIL' AND PAID = 'pending' "));
更新2
输出 50 | 预期 25
答案 0 :(得分:0)
尝试查询
SELECT SUM(FEE) FROM clients
INNER JOIN payments ON payments.ID = clients.SID AND PAID = 'pending'
WHERE clients.EMAIL = '$EMAIL'