Wednesday, September 22, 2010

Calculate percentages

There are three tables housing information related to a person set up in a bank, his accounts and his transactions. The following is the anatomy of the tables

PERSON
ID
FIRST_NAME
LAST_NAME

ACCOUNTS
ID
PERSON_ID ( fk to ID in person table)
ACCOUNT_TYPE( Savings/Checkings/illegal )

TRANSACTIONS
ID
ACCOUNT_ID ( fk to ID in accounts table )
DATE
TRANSACTION_AMOUNT

Calculate the percentage of the total amount owned by a person in each of the accoutns that he has.

The results set should look like this

PERSON : ACCOUNT : MONEY IN ACCT : PERCENTAGE OF TOTAL MONEY
JOE, CHK, 500, 50%
JOE, SAV, 500, 50%

Write an sql query to accomplish this in two fairly different ways.

No comments:

Post a Comment