RDBMS Questions and Answers – SQL Queries – IV

This set of RDBMS Assessment Questions and Answers focuses on “Sql Queries – IV”.

1. Find all the customers who have both a loan and an account at the Perryridge branch
View Answer

Answer: select customer_name from loan natural join borrower
where branch_name = ‘Perryridge’ and
customer_name in
(select customer_name from account natural join depositor
where branch_name = ‘Perryridge’);

2. Find all customers who do have a loan at the bank, but do not have an account at the bank.
View Answer

Answer: select customer_name from loan natural join borrower
where customer_name not in
(select customer_name from account natural join depositor);

3. Select the names of customers who have a loan at the bank, and whose names are neither Smith nor Jones
View Answer

Answer: select customer_name from loan natural join borrower
where branch_name = ‘Perryridge’ and customer_name not in
(‘Smith’, ‘Jones’);
advertisement
advertisement

4. Find the names of all branches that have assets greater than those of at least one branch located in Brooklyn.
View Answer

Answer: select branch_name from branch where
assets > some(select assets from branch
where branch_city = ‘Brooklyn’);

5. Find the names of all branches that have an asset value greater than that of each branch in Brooklyn.
View Answer

Answer: select branch_name from branch where
assets > some(select assets from branch
where branch_city = ‘Brooklyn’);
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Find all customers who have both an account and a loan at the bank
View Answer

Answer: select distinct customer_name from borrower as b1
where exists (select customer_name from depositor as b2
where b1.customer_name = b2.customer_name);

7. Find all customers who have an account at all the branches located in Brooklyn.
View Answer

Answer: select customer_name from
account as b1 natural join depositor
where exists (select * from branch
where b1.branch_name = ‘Downtown’
and b1.branch_name=’Brighton’);
advertisement

8. Find all customers who have at most one account at the Perryridge branch
View Answer

Answer: select customer_name from account natural join depositor
where branch_name = ‘Perryridge’ group by customer_name
having count(account_number)<=1;

9. Find all customers who have at least two accounts at the perryridge branch
View Answer

Answer: select customer_name from account natural join depositor
where branch_name = ‘Perryridge’ group by customer_name
having count(account_number)>=2;
advertisement

Complex queries
10. Find the average account balance of those branches where the account balance is greater than Rs. 1200.
View Answer

Answer: select avg(balance),branch_name from account
where balance > 1200 group by branch_name;

Sanfoundry Global Education & Learning Series – RDBMS.

To practice all areas of RDBMS Assessment Questions, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.