Question in SQL...
Date: 30 Jan 2002 03:36:11 -0800
Message-ID: <aa643641.0201300336.14bba0d4_at_posting.google.com>
Hi All,
This question I found in one of the exam papers.
Q> Consider a bank database with only one relation
transaction(transno, acctno, date, amount)
The amount attribute value is positive for deposits and negative for withdrawals.
(a) Define an SQL view TP containing the information (acctno,
T1.date, T2.amount) for every pair of transactions T1, T2 such that T1
an T2 are transactions on same account and the date of T2 is <= date
of T1.
(b) Using only the above view TP, write a query to find for each
account the minimum balance it ever reached (not including the balance
when the account is created). Assume there is atmost one transaction
per day on each account, and each account has had atleast one
transaction since it was created.
To simplify your query, break it up into 2 steps by defining an
intermediate view V.
For the (a) part I feel the query to be as follows:
create view TP(acctno, T1.date, T2.amount) as (select T1.acctno, T1.date, T2.amount from transaction as T1, transaction as T2 where T1.acctno = T2.acctno
and T2.date <= T1.date)
Please check the query for (a) I have written. And suggest me query for part (b).
Thanx.
Harshad Warnekar. Received on Wed Jan 30 2002 - 12:36:11 CET