CREATE TABLE ACCOUNTS (
    custid NUMBER PRIMARY KEY,
    name TEXT
);
CREATE TABLE SAVINGS (
    custid NUMBER PRIMARY KEY,
    balance NUMBER,
    FOREIGN KEY ("custid") REFERENCES ACCOUNTS("custid")
);
CREATE TABLE CHECKING (
    custid NUMBER PRIMARY KEY,
    balance NUMBER,
    FOREIGN KEY ("custid") REFERENCES ACCOUNTS("custid")
);

Question: Find the total savings balance of all accounts except the account with name ‘Brown’.
SQL: SELECT sum(T2.balance) FROM accounts AS T1 JOIN savings AS T2 ON T1.custid  =  T2.custid WHERE T1.name != 'Brown'

Question: What is the total balance of savings accounts not belonging to someone with the name Brown?
SQL: SELECT sum(T2.balance) FROM accounts AS T1 JOIN savings AS T2 ON T1.custid  =  T2.custid WHERE T1.name != 'Brown'

Question: How many accounts are there in total?
SQL: SELECT count(*) FROM accounts

Question: Count the number of accounts.
SQL: SELECT count(*) FROM accounts

Question: What is the total checking balance in all accounts?
SQL: SELECT sum(balance) FROM checking

Question: Find the total balance across checking accounts.
SQL: SELECT sum(balance) FROM checking

Question: Find the average checking balance.
SQL: SELECT avg(balance) FROM checking

Question: What is the average balance in checking accounts?
SQL: SELECT avg(balance) FROM checking

Question: How many accounts have a savings balance above the average savings balance?
SQL: SELECT count(*) FROM savings WHERE balance  >  (SELECT avg(balance) FROM savings)

Question: Find the number of accounts with a savings balance that is higher than the average savings balance.
SQL: SELECT count(*) FROM savings WHERE balance  >  (SELECT avg(balance) FROM savings)

Question: Find the name and id of accounts whose checking balance is below the maximum checking balance.
SQL: SELECT T1.custid ,  T1.name FROM accounts AS T1 JOIN checking AS T2 ON T1.custid  =  T2.custid WHERE T2.balance  <  (SELECT max(balance) FROM checking)

Question: What are the customer id and name corresponding to accounts with a checking balance less than the largest checking balance?
SQL: SELECT T1.custid ,  T1.name FROM accounts AS T1 JOIN checking AS T2 ON T1.custid  =  T2.custid WHERE T2.balance  <  (SELECT max(balance) FROM checking)

Question: What is the checking balance of the account whose owner’s name contains the substring ‘ee’?
SQL: SELECT T2.balance FROM accounts AS T1 JOIN checking AS T2 ON T1.custid  =  T2.custid WHERE T1.name LIKE '%ee%'

Question: Find the balance of the checking account belonging to an owner whose name contains 'ee'.
SQL: SELECT T2.balance FROM accounts AS T1 JOIN checking AS T2 ON T1.custid  =  T2.custid WHERE T1.name LIKE '%ee%'

Question: Find the checking balance and saving balance in the Brown’s account.
SQL: 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'

Question: What are the checking and savings balances in accounts belonging to Brown?
SQL: 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'

Question: Find the names of accounts whose checking balance is above the average checking balance, but savings balance is below the average savings balance.
SQL: 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)

Question: What are the names of accounts with checking balances greater than the average checking balance and savings balances below the average savings balance?
SQL: 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)

Question: Find the checking balance of the accounts whose savings balance is higher than the average savings balance.
SQL: SELECT T2.balance FROM accounts AS T1 JOIN checking AS T2 ON T1.custid  =  T2.custid WHERE T1.name IN (SELECT T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid  =  T2.custid WHERE T2.balance  >  (SELECT avg(balance) FROM savings))

Question: What are the balances of checking accounts belonging to people with savings balances greater than the average savings balance?
SQL: SELECT T2.balance FROM accounts AS T1 JOIN checking AS T2 ON T1.custid  =  T2.custid WHERE T1.name IN (SELECT T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid  =  T2.custid WHERE T2.balance  >  (SELECT avg(balance) FROM savings))

Question: List all customers’ names in the alphabetical order.
SQL: SELECT name FROM accounts ORDER BY name

Question: What are the names of all the customers in alphabetical order?
SQL: SELECT name FROM accounts ORDER BY name

Question: Find the name of account that has the lowest total checking and saving balance.
SQL: 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 ORDER BY T2.balance + T3.balance LIMIT 1

Question: What is the name corresponding to the accoung with the lowest sum of checking and savings balances?
SQL: 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 ORDER BY T2.balance + T3.balance LIMIT 1

Question: Find the names and total checking and savings balances of accounts whose savings balance is higher than the average savings balance.
SQL: SELECT T1.name ,  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 T3.balance  >  (SELECT avg(balance) FROM savings)

Question: What are the names and sum of checking and savings balances for accounts with savings balances higher than the average savings balance?
SQL: SELECT T1.name ,  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 T3.balance  >  (SELECT avg(balance) FROM savings)

Question: Find the name and checking balance of the account with the lowest savings balance.
SQL: SELECT T1.name ,  T2.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 T3.balance LIMIT 1

Question: What are the names and balances of checking accounts belonging to the customer with the lowest savings balance?
SQL: SELECT T1.name ,  T2.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 T3.balance LIMIT 1

Question: Find the number of checking accounts for each account name.
SQL: SELECT count(*) ,  T1.name FROM accounts AS T1 JOIN checking AS T2 ON T1.custid  =  T2.custid GROUP BY T1.name

Question: What are the names of customers with accounts, and how many checking accounts do each of them have?
SQL: SELECT count(*) ,  T1.name FROM accounts AS T1 JOIN checking AS T2 ON T1.custid  =  T2.custid GROUP BY T1.name

Question: Find the total saving balance for each account name.
SQL: SELECT sum(T2.balance) ,  T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid  =  T2.custid GROUP BY T1.name

Question: What are the names of customers with accounts, and what are the total savings balances for each?
SQL: SELECT sum(T2.balance) ,  T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid  =  T2.custid GROUP BY T1.name

Question: Find the name of accounts whose checking balance is below the average checking balance.
SQL: SELECT T1.name FROM accounts AS T1 JOIN checking AS T2 ON T1.custid  =  T2.custid WHERE T2.balance  <  (SELECT avg(balance) FROM checking)