100% found this document useful (1 vote)
157 views1 page

Database Cse370 Lab 5 Bracu

This document contains 15 SQL queries that join various tables like customer, depositor, account, loan, and branch to retrieve customer information, account details, loan amounts, branch assets and more. The queries use joins, filters, aggregation, sorting and limiting to select specific fields and rows from the tables.

Uploaded by

Sabbir Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
157 views1 page

Database Cse370 Lab 5 Bracu

This document contains 15 SQL queries that join various tables like customer, depositor, account, loan, and branch to retrieve customer information, account details, loan amounts, branch assets and more. The queries use joins, filters, aggregation, sorting and limiting to select specific fields and rows from the tables.

Uploaded by

Sabbir Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

select * from customer inner join depositor on

customer.customer_id=depositor.customer_id;
select * from customer left join depositor on
customer.customer_id=depositor.customer_id;
select * from customer right join depositor on
customer.customer_id=depositor.customer_id;
select * from ((customer left join depositor on
customer.customer_id=depositor.customer_id)left join account on
depositor.account_number=account.account_number);
select customer_name,customer_city,account.account_number,balance,branch_name from
((customer left join depositor on customer.customer_id=depositor.customer_id)left
join account on depositor.account_number=account.account_number);
select customer_name,customer_city,account.account_number,balance,branch_name from
customer,depositor,account where customer.customer_id=depositor.customer_id and
depositor.account_number=account.account_number;
select customer_name,customer_city from customer,borrower,loan where
customer.customer_id=borrower.customer_id and borrower.loan_number=loan.loan_number
and loan.branch_name="perryridge";
select account_number from account where balance between 700 and 900;
select customer_name from customer where customer_street like "%hill";
select branch_name from branch where assets> any(select assets from branch);
select branch_name from branch where assets> all(select assets from branch where
branch_name="horseneck");
select * from loan order by amount desc,loan_number asc;
select branch_name, avg(balance) from account group by branch_name having
avg(balance) >= 700;
select customer.customer_name,account.account_number from
customer,depositor,account where customer.customer_id=depositor.customer_id and
depositor.account_number=account.account_number order by balance desc limit 3;
select customer_name from((customer left join depositor on
customer.customer_id=depositor.customer_id)left join account on
account.account_number=depositor.account_number) where branch_name in(select
branch_name from((customer left join depositor on
customer.customer_id=depositor.customer_id)left join account on
account.account_number=depositor.account_number) where customer_name="johnson");
select customer_name from customer where customer.customer_id in (select
customer_id from depositor where depositor.account_number in (select account_number
from account where branch_name="mianus")) and customer.customer_id not in (select
customer_id from borrower where borrower.loan_number in(select loan_number from
loan where branch_name="mianus"));
select branch_name, count(distinct account.account_number) from depositor, account,
customer where depositor.customer_id = customer.customer_id and
depositor.account_number = account.account_number group by branch_name having
count(distinct account.account_number) >= 1;
select avg(balance) from depositor, account, customer where depositor.customer_id =
customer.customer_id and depositor.account_number = account.account_number and
customer_city ='Palo Alto' group by customer_name having count(distinct
account.account_number) >= 2;
select customer.customer_name,account.account_number from
customer,depositor,account where customer.customer_id=depositor.customer_id and
depositor.account_number=account.account_number order by balance desc limit 2,1;

You might also like