Professional Documents
Culture Documents
SQL
SQL
Branch: bname (assuming that each branch name is unique within the organization)
Customer: ID (assuming that each customer has a unique ID)
Loan: loan_no (assuming that each loan has a unique loan number)
Borrower: (ID, loan_no) (assuming that each customer can have only one loan at a
time and vice versa)
Account: acc_no (assuming that each account has a unique account number)
Depositor: (ID, acc_no) (assuming that each customer has only one account at a time
and vice versa)
π(ID)(σ(bname = "Downtown")(borrower))
This expression uses the selection (σ) operator to select the rows from the
borrower relation where the bname attribute is
equal to "Downtown". Then it uses the projection (π) operator to select the ID
attribute from the resulting rows.
3.Find each loan number with a loan amount greater than $10000:
4. Find the ID of each depositor who has an account with a balance greater than
$6000:
5. Find the ID of each depositor who has an account with a balance greater than
$6000 at the "Uptown" branch:
This expression uses the natural join (⨝) operator to join the depositor and
account relations on the ID and acc_no
attributes, respectively. Then it uses the selection (σ) operator to select the
rows where the bname attribute is equal to
"Uptown" and the balance attribute is greater than $6000. Finally, it uses the
projection (π) operator to select the ID
attribute from the resulting rows.
This SQL statement uses the SUM aggregate function to calculate the total sum of
all loan amounts.
Here are the corrected SQL statements for the given requirements:
Find the ID of each customer who has an account but not a loan:
SELECT SUM(loan.amount)
FROM loan;
Find the names of all branches that have assets greater than those of at least one
branch located in "Brooklyn":
UPDATE employee
SET city = 'Newton'
WHERE ID = '12345';