How many customers have loans that total more than 5000?
select count ( * ) from ( select * 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 )
What are their names?
select cust_name 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
What is her account balance?
select t1.acc_bal 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