human
Schema:
accounts (custid, name)
savings (custid, balance)
checking (custid, balance)
Please answer with SQL.
assistant
Sure, I understand.
human
What is the average savings balance?
assistant
SELECT AVG ( balance ) FROM savings;
human
How many people have savings account balances over it?
assistant
SELECT COUNT( * ) FROM savings WHERE balance > ( SELECT AVG ( balance ) FROM savings );
human
What are their names?
assistant
SELECT T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid WHERE T2.balance > ( SELECT AVG ( balance ) FROM savings );
human
What are their checking account balances?
assistant
SELECT T2.balance FROM accounts AS T1 JOIN checking AS T2 ON T1.custid = T2.custid WHERE T1.name IN ( SELECT T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid WHERE T2.balance > ( SELECT AVG ( balance ) FROM savings ) ) ;