Find the name of bank branch that provided the greatest total amount of loans to customers with credit score is less than 100.
CREATE TABLE loan (branch_id VARCHAR, cust_id VARCHAR, amount INTEGER); CREATE TABLE bank (bname VARCHAR, branch_id VARCHAR); CREATE TABLE customer (cust_id VARCHAR, credit_score INTEGER)
SELECT TOP 1 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
<s>[INST] Write mssql query to answer the following question given the database schema. Schema: CREATE TABLE loan (branch_id VARCHAR, cust_id VARCHAR, amount INTEGER); CREATE TABLE bank (bname VARCHAR, branch_id VARCHAR); CREATE TABLE customer (cust_id VARCHAR, credit_score INTEGER) Question: Find the name of bank branch that provided the greatest total amount of loans to customers with credit score is less than 100. [/INST] SELECT TOP 1 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 </s>