create table account ( id int(11), state varchar(2) ); create table transaction ( id int(11), user_id int(11), amount int(6), added timestamp );
select sum(transaction.amount) from transaction, account where transaction.id = account.id AND account.state = 'TX' AND transaction.added between '20030101000000' and '20031231235959'; On Mon, 2004-03-15 at 14:37, Scott Haneda wrote: > Account table has a field state and a field id. > Transaction table has fields id, user_id, amount, added > > Id is the PK in the account table, related to the user_id in the transaction > table. > > I need to get a sum of the amount column for all users in state of TX in the > year of 2003. > > Tried a few ways, cant seem to get this one. So, given: create table account ( id int(11), state varchar(2) ); create table transaction ( id int(11), user_id int(11), amount int(6), added timestamp ); Did you try: select sum(transaction.amount) from transaction, account where transaction.id = account.id AND account.state = 'TX' AND transaction.added between '20030101000000' and '20031231235959'; ? -- |- Garth Webb -| |- [EMAIL PROTECTED] -|
signature.asc
Description: This is a digitally signed message part