I am trying to get the sum of the rows that belong to particular account_ids, but I am getting the sum for the complete column, regardless of id. Here is my sql statement.
$sql = 'SELECT a.id, a.name, at.name AS type, sum(t.amount) AS amount FROM accounts a INNER JOIN account_types at ON a.account_type_id=at.id INNER JOIN transactions t ON a.id=t.account_id WHERE t.account_id=a.id';
account_types has id, name.
accounts has id, name, account_type_id
transactions has id, date, account_id, amount
Am I going about this in the completely wrong direction?
Any suggestions on the proper sql statement, or directions to stuff I should read to get a better understanding of what I need would be greatly appreciated.
Thanks,
Michael