human
Schema:
accounts (custid, name)
savings (custid, balance)
checking (custid, balance)
Please answer with SQL.
assistant
Sure, I understand.
human
Can you tell me the average checking balance of all checking accounts?
assistant
SELECT AVG ( balance ) FROM checking;
human
Hmm, I also want to know the average savings balance of all savings accounts.
assistant
SELECT AVG ( balance ) FROM savings;
human
Can you list the names of accounts whose checking balance is above the average checking balance, but savings balance is below the average savings balance?
assistant
SELECT T1.name FROM accounts AS T1 JOIN checking AS T2 ON T1.custid = T2.custid WHERE T2.balance > ( SELECT AVG ( balance ) FROM checking ) INTERSECT SELECT T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid WHERE T2.balance < ( SELECT AVG ( balance ) FROM savings ) ;