Database: customers_and_invoices

Question: Show the id, the date of account opened, the account name, and other account detail for all accounts.
SQL: SELECT account_id ,  date_account_opened ,  account_name ,  other_account_details FROM Accounts

Question: Show the id, the account name, and other account details for all accounts by the customer with first name 'Meaghan'.
SQL: SELECT T1.account_id ,  T1.date_account_opened ,  T1.account_name ,  T1.other_account_details FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id  =  T2.customer_id WHERE T2.customer_first_name  =  'Meaghan'

Question: Show the account name and other account detail for all accounts by the customer with first name Meaghan and last name Keeling.
SQL: SELECT T1.account_name ,  T1.other_account_details FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id  =  T2.customer_id WHERE T2.customer_first_name  =  "Meaghan" AND T2.customer_last_name  =  "Keeling"

Question: Show the first name and last name for the customer with account name 900.
SQL: SELECT T2.customer_first_name ,  T2.customer_last_name FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id  =  T2.customer_id WHERE T1.account_name  =  "900"

Question: Show the unique first names, last names, and phone numbers for all customers with any account.
SQL: SELECT DISTINCT T1.customer_first_name ,  T1.customer_last_name ,  T1.phone_number FROM Customers AS T1 JOIN Accounts AS T2 ON T1.customer_id  =  T2.customer_id

Question: Show customer ids who don't have an account.
SQL: SELECT customer_id FROM Customers EXCEPT SELECT customer_id FROM Accounts

Question: How many accounts does each customer have? List the number and customer id.
SQL: SELECT count(*) ,  customer_id FROM Accounts GROUP BY customer_id

Question: What is the customer id, first and last name with most number of accounts.
SQL: SELECT T1.customer_id ,  T2.customer_first_name ,  T2.customer_last_name FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id  =  T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1

Question: Show id, first name and last name for all customers and the number of accounts.
SQL: SELECT T1.customer_id ,  T2.customer_first_name ,  T2.customer_last_name ,  count(*) FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id  =  T2.customer_id GROUP BY T1.customer_id

Question: Show first name and id for all customers with at least 2 accounts.
SQL: SELECT T2.customer_first_name ,  T1.customer_id FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id  =  T2.customer_id GROUP BY T1.customer_id HAVING count(*)  >=  2

Question: Show the number of customers for each gender.
SQL: SELECT gender ,  count(*) FROM Customers GROUP BY gender

Question: How many transactions do we have?
SQL: SELECT count(*) FROM Financial_transactions

Question: How many transaction does each account have? Show the number and account id.
SQL: SELECT count(*) ,  account_id FROM Financial_transactions

Question: How many transaction does account with name 337 have?
SQL: SELECT count(*) FROM Financial_transactions AS T1 JOIN Accounts AS T2 ON T1.account_id  =  T2.account_id WHERE T2.account_name  =  "337"