human
Schema:
accounts (custid, name)
savings (custid, balance)
checking (custid, balance)
Please answer with SQL.
assistant
Sure, I understand.
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 name of accounts whose checking balance is higher than corresponding saving balance.
assistant
SELECT T1.name FROM accounts AS T1 JOIN checking AS T2 ON T1.custid = T2.custid JOIN savings AS T3 ON T1.custid = T3.custid WHERE T2.balance > T3.balance
human
How many accounts have a savings balance above the average savings balance?
assistant
SELECT count(*) FROM savings WHERE balance > (SELECT avg(balance) FROM savings)
human
What is the total checking balance in all accounts?
assistant
SELECT sum(balance) FROM checking
human
Find the total savings balance of all accounts except the account with name Brown .
assistant
SELECT sum(T2.balance) FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid WHERE T1.name != 'Brown'
human
What are the checking and savings balances in accounts belonging to Brown?
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 T1.name = "Brown" ;