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;
human
What is the name on the account with the lowest balance? | The name of the account with the lowest saving balance is Weeks | What is the name on the account with the third highest saving balance?
assistant
SELECT T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid ORDER by T2.balance desc LIMIT 3 ;