group by? sum? help.

admin

Administrator
Staff member
Howdy,

I have a transactions table that contains all the account transactions for multiple accounts. There is a column that identifies which account the row belongs to. I would like to create a page where a user can view all of his own accounts (did I mention one user can have several accounts?) as well as the sum/balance of each account. I was hoping this could all be done in one SQL statement (MySQL BTW).

something like:

select *, sum(amount) as sum from transactions where account_number=132 or account_number=174 group by account_number sort by date

ideally producing results like:

Account 132
. entry1 amount1 date1
. entry2 amount2 date2
. entry13 amount13 date13
balance: sum(amounts)

Account 174
. entry7 amount7 date7
. entry10 amount10 date10
balance sum(amounts)

I actually haven't tried to make the sql statement yet, I was hoping some of you might save me some hair-pulling... :-)
 
Back
Top