Database: customers_and_addresses

Question: What are the names of all the customers?
SQL: SELECT customer_name FROM customers

Question: Return the total number of distinct customers.
SQL: SELECT count(*) FROM customers

Question: Find the average order quantity per order.
SQL: SELECT avg(order_quantity) FROM order_items

Question: Which customers use "Cash" for payment method? Return the customer names.
SQL: SELECT customer_name FROM customers WHERE payment_method  =  "Cash"

Question: What are the dates when customers with ids between 10 and 20 became customers?
SQL: SELECT date_became_customer FROM customers WHERE customer_id BETWEEN 10 AND 20

Question: Find the payment method that is used most frequently.
SQL: SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1

Question: Find the name of the customers who use the most frequently used payment method.
SQL: SELECT customer_name FROM customers WHERE payment_method  =  (SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1)

Question: Return all the distinct payment methods used by customers.
SQL: SELECT DISTINCT payment_method FROM customers

Question: Return the the details of all products.
SQL: SELECT DISTINCT product_details FROM products

Question: Which customer's name contains "Alex"? Find the full name.
SQL: SELECT customer_name FROM customers WHERE customer_name LIKE "%Alex%"

Question: Which product's detail contains the word "Latte" or "Americano"? Return the full detail.
SQL: SELECT product_details FROM products WHERE product_details LIKE "%Latte%" OR product_details LIKE "%Americano%"

Question: Return the address content for the customer whose name is "Maudie Kertzmann".
SQL: SELECT t3.address_content FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id  =  t2.customer_id JOIN addresses AS t3 ON t2.address_id  =  t3.address_id WHERE t1.customer_name  =  "Maudie Kertzmann"

Question: Find the number of customers who live in the city called Lake Geovannyton.
SQL: SELECT count(*) FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id  =  t2.customer_id JOIN addresses AS t3 ON t2.address_id  =  t3.address_id WHERE t3.city  =  "Lake Geovannyton"

Question: What are the names of customers who live in Colorado state?
SQL: SELECT t1.customer_name FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id  =  t2.customer_id JOIN addresses AS t3 ON t2.address_id  =  t3.address_id WHERE t3.state_province_county  =  "Colorado"

Question: What are the cities no customers live in?
SQL: SELECT city FROM addresses WHERE city NOT IN ( SELECT DISTINCT t3.city FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id  =  t2.customer_id JOIN addresses AS t3 ON t2.address_id  =  t3.address_id)

Question: Find the city where the most customers live.
SQL: SELECT t3.city FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id  =  t2.customer_id JOIN addresses AS t3 ON t2.address_id  =  t3.address_id GROUP BY t3.city ORDER BY count(*) DESC LIMIT 1

Question: List all the distinct cities
SQL: SELECT DISTINCT city FROM addresses