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
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, 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
Find the average credit score of the customers who have some loan.
assistant
SELECT avg(credit_score) FROM customer WHERE cust_id IN (SELECT cust_id FROM loan)
human
Find the average credit score of the customers who do not have any loan.
assistant
SELECT avg(credit_score) FROM customer WHERE cust_id NOT IN (SELECT cust_id FROM loan)
human
Find the name of customer who has the lowest credit score.
assistant
SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1
human
Find the name of customers whose credit score is below the average credit scores of all customers.
assistant
SELECT cust_name FROM customer WHERE credit_score < ( SELECT avg ( credit_score ) FROM customer ) ;