human
Schema:
accounts (custid, name)
savings (custid, balance)
checking (custid, balance)
Please answer with SQL.
assistant
Sure, I understand.
human
Find the name and total checking and savings balance of the accounts whose savings balance is lower than corresponding checking balance.
assistant
SELECT T1.name , T3.balance + T2.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 < T2.balance
human
Find the total saving balance for each account name.
assistant
SELECT sum(T2.balance) , T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid GROUP BY T1.name
human
Find the total checking and saving balance of all accounts sorted by the total balance in ascending order.
assistant
SELECT T1.balance + T2.balance FROM checking AS T1 JOIN savings AS T2 ON T1.custid = T2.custid ORDER BY T1.balance + T2.balance
human
Find the average checking balance.
assistant
SELECT avg(balance) FROM checking
human
Find the saving balance of the account with the highest checking balance.
assistant
SELECT T3.balance FROM accounts AS T1 JOIN checking AS T2 ON T1.custid = T2.custid JOIN savings AS T3 ON T1.custid = T3.custid ORDER BY T2.balance DESC LIMIT 1
human
Find the total balance across checking accounts.
assistant
SELECT SUM( balance ) FROM checking ;