Database: driving_school

Question: In which city live the most staff? List the city name and number of staff.
SQL: SELECT T1.city ,  count(*) FROM Addresses AS T1 JOIN Staff AS T2 ON T1.address_id = T2.staff_address_id GROUP BY T1.city ORDER BY count(*) DESC LIMIT 1;

Question: List the states which have between 2 to 4 staff living there.
SQL: SELECT T1.state_province_county FROM Addresses AS T1 JOIN Staff AS T2 ON T1.address_id = T2.staff_address_id GROUP BY T1.state_province_county HAVING count(*) BETWEEN 2 AND 4;

Question: What is the status code, mobile phone number and email address of the customer with last name as Kohler or first name as Marina?
SQL: SELECT customer_status_code ,  cell_mobile_phone_number ,  email_address FROM Customers WHERE first_name = "Marina" OR last_name  =  "Kohler"

Question: When did customer with first name as Carole and last name as Bernhard became a customer?
SQL: SELECT date_became_customer FROM Customers WHERE first_name = "Carole" AND last_name = "Bernhard";

Question: Which customer status code has least number of customers?
SQL: SELECT customer_status_code FROM Customers GROUP BY customer_status_code ORDER BY count(*) ASC LIMIT 1;

Question: How many lessons taken by customer with first name as Rylan and last name as Goodwin were completed?
SQL: SELECT count(*) FROM Lessons AS T1 JOIN Customers AS T2 ON T1.customer_id  = T2.customer_id WHERE T2.first_name = "Rylan" AND T2.last_name = "Goodwin" AND T1.lesson_status_code = "Completed";

Question: What is maximum, minimum and average amount of outstanding of customer?
SQL: SELECT max(amount_outstanding) ,  min(amount_outstanding) ,  avg(amount_outstanding) FROM Customers;

Question: List first name and last name of customers living in city Lockmanfurt.
SQL: SELECT T1.first_name ,  T1.last_name FROM Customers AS T1 JOIN Addresses AS T2 ON T1.customer_address_id = T2.address_id WHERE T2.city = "Lockmanfurt";

Question: Which country does customer with first name as Carole and last name as Bernhard live in?
SQL: SELECT T2.country FROM Customers AS T1 JOIN Addresses AS T2 ON T1.customer_address_id = T2.address_id WHERE T1.first_name = "Carole" AND T1.last_name = "Bernhard"

Question: What is zip code of customer with first name as Carole and last name as Bernhard?
SQL: SELECT T2.zip_postcode FROM Customers AS T1 JOIN Addresses AS T2 ON T1.customer_address_id = T2.address_id WHERE T1.first_name = "Carole" AND T1.last_name = "Bernhard"

Question: Which city has most number of customers?
SQL: SELECT T2.city FROM Customers AS T1 JOIN Addresses AS T2 ON T1.customer_address_id = T2.address_id GROUP BY T2.city ORDER BY count(*) DESC LIMIT 1;

Question: How much in total has customer with first name as Carole and last name as Bernhard paid?
SQL: SELECT sum(T1.amount_payment) FROM Customer_Payments AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.first_name = "Carole" AND T2.last_name = "Bernhard"

Question: List the number of customers that did not have any payment history.
SQL: SELECT count(*) FROM Customers WHERE customer_id NOT IN ( SELECT customer_id FROM Customer_Payments );