Database: loan_1

Question: Find the total amount of loans offered by each bank branch.
SQL: SELECT sum(amount) ,  T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id  =  T2.branch_id GROUP BY T1.bname

Question: Find the name of customers who have more than one loan.
SQL: SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id  =  T2.cust_id GROUP BY T1.cust_name HAVING count(*)  >  1

Question: Find the name and account balance of the customers who have loans with a total amount of more than 5000.
SQL: SELECT T1.cust_name ,  T1.acc_type FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id  =  T2.cust_id GROUP BY T1.cust_name HAVING sum(T2.amount)  >  5000

Question: Find the name of bank branch that provided the greatest total amount of loans.
SQL: SELECT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id  =  T2.branch_id GROUP BY T1.bname ORDER BY sum(T2.amount) DESC LIMIT 1

Question: Find the name of bank branch that provided the greatest total amount of loans to customers with credit score is less than 100.
SQL: SELECT T2.bname FROM loan AS T1 JOIN bank AS T2 ON T1.branch_id  =  T2.branch_id JOIN customer AS T3 ON T1.cust_id  =  T3.cust_id WHERE T3.credit_score  <  100 GROUP BY T2.bname ORDER BY sum(T1.amount) DESC LIMIT 1

Question: Find the the name of the customers who have a loan with amount more than 3000.
SQL: SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id  =  T2.cust_id WHERE amount  >  3000

Question: Find the city and name of bank branches that provide business loans.
SQL: SELECT T1.bname,  T1.city FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id  =  T2.branch_id WHERE T2.loan_type  =  'Business'

Question: Find the names of bank branches that have provided a loan to any customer whose credit score is below 100.
SQL: SELECT T2.bname FROM loan AS T1 JOIN bank AS T2 ON T1.branch_id  =  T2.branch_id JOIN customer AS T3 ON T1.cust_id  =  T3.cust_id WHERE T3.credit_score  <  100

Question: Find the total amount of loans provided by bank branches in the state of New York.
SQL: SELECT sum(T2.amount) FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id  =  T2.branch_id WHERE T1.state  =  'New York'

Question: Find the average credit score of the customers who have some loan.
SQL: SELECT avg(credit_score) FROM customer WHERE cust_id IN (SELECT cust_id FROM loan)