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.

Tuesday, September 21, 2010

Assignment 1 Printing numbers

Print numbers 1-10 in sql

Solution:

We can execute the solution in many ways.

A couple of them are :

Solution 1

SELECT rownum as num FROM transaction
WHERE rownum <= 10

or if I were to use level ;

Solution 2

SELECT Level as num
FROM dual
CONNECT BY Level <=10

If you have any questions or better solutions, please post comments.