将table_a与table_b的多个结果链接起来

时间:2015-03-28 12:14:55

标签: mysql

所以这是我目前拥有的代码,它打印一个列表,如:

accounts_id accounts_amount

payments_date payments_amount

$stmt = $db->query("SELECT * FROM debt_accounts INNER JOIN debt_payments ON payments_account=accounts_id  ORDER BY accounts_id ASC, payments_date ASC");

$num =  $stmt->rowCount();
$current_price = "";                                

for($i=0;$i<$num;$i++){$row = $stmt->fetch(PDO::FETCH_ASSOC);                               
if($row['accounts_id'] != $current_price) {
echo'<h3>'.$row['accounts_id'].' <font></font></h3>';
$current_price = $row['accounts_id'];
}

echo''.$row['payments_date'].' - '.$row['payments_amount'].' <br />';

}

所以现在我想在同一个查询中做什么,如果可能的话,accounts_amount值是我想要的那个

accounts_amount - SUM(payments_amount)

非常感谢任何帮助。

0 个答案:

没有答案