human
Schema:
accounts (custid, name)
savings (custid, balance)
checking (custid, balance)
Please answer with SQL.
assistant
Sure, I understand.
human
Hi, could you please let me know what is the average savings balance of all customers?
assistant
SELECT AVG ( balance ) FROM savings;
human
Awesome, thank you. Then could you please show me the ID of the customers who have higher balance than this average?
assistant
SELECT custid FROM savings WHERE balance > ( SELECT AVG ( balance ) FROM savings );
human
oh that's a bit surprising, maybe this person is elevating the average a lot. Thank you, then could you please show me this customer's balance on both CHECKING and SAVINGS table?
assistant
SELECT T2.balance , T3.balance FROM accounts AS T1 JOIN checking AS T2 ON T1.custid = T2.custid JOIN savings AS T3 ON T1.custid = T3.custid WHERE T3.balance > ( SELECT AVG ( balance ) FROM savings ) ;