human
Schema:
bank (branch_ID, bname, no_of_customers, city, state)
customer (cust_ID, cust_name, acc_type, acc_bal, no_of_loans, credit_score, branch_ID, state)
loan (loan_ID, loan_type, cust_ID, branch_ID, amount)
Please answer with SQL.
assistant
Sure, I understand.
human
Find the average number of customers cross all banks.
assistant
SELECT avg(no_of_customers) FROM bank
human
Find the branch name of the bank that has the most number of customers.
assistant
SELECT bname FROM bank ORDER BY no_of_customers DESC LIMIT 1
human
Find the name, account type, and account balance of the customer who has the highest credit score.
assistant
SELECT cust_name , acc_type , acc_bal FROM customer ORDER BY credit_score DESC LIMIT 1
human
For each account type, find the average account balance of customers with credit score lower than 50.
assistant
SELECT avg(acc_bal) , acc_type FROM customer WHERE credit_score < 50 GROUP BY acc_type
human
Find the name of customers who have both saving and checking account types.
assistant
SELECT cust_name FROM customer WHERE acc_type = 'saving' INTERSECT SELECT cust_name FROM customer WHERE acc_type = 'checking'
human
Count the number of different account types.
assistant
SELECT COUNT( DISTINCT acc_type ) FROM customer ;