human
Schema:
accounts (custid, name)
savings (custid, balance)
checking (custid, balance)
Please answer with SQL.
assistant
Sure, I understand.
human
Find the name of the top 3 accounts with the highest saving balance sorted by savings balance in descending order.
assistant
SELECT T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid ORDER BY T2.balance DESC LIMIT 3;
human
Can you add in their customer IDs to the table please?
assistant
SELECT T1.name , T2.custid FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid ORDER BY T2.balance DESC LIMIT 3;
human
What is the average balance of all accounts?
assistant
SELECT AVG ( T2.balance ) FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid ;