Database: customers_and_addresses

Question: Find the number of distinct products Rodrick Heaney has bought so far.
SQL: SELECT count(DISTINCT product_id) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id JOIN order_items AS t3 ON t2.order_id  =  t3.order_id WHERE t1.customer_name  =  "Rodrick Heaney"

Question: Tell me the total quantity of products bought by the customer called "Rodrick Heaney".
SQL: SELECT sum(t3.order_quantity) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id JOIN order_items AS t3 ON t2.order_id  =  t3.order_id WHERE t1.customer_name  =  "Rodrick Heaney"

Question: Return the number of customers who have at least one order with "Cancelled" status.
SQL: SELECT count(DISTINCT customer_id) FROM customer_orders WHERE order_status  =  "Cancelled"

Question: Tell me the number of orders with "Second time" as order detail.
SQL: SELECT count(*) FROM customer_orders WHERE order_details  =  "Second time"

Question: What are the customer name and date of the orders whose status is "Delivered".
SQL: SELECT t1.customer_name ,  t2.order_date FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id WHERE order_status  =  "Delivered"

Question: Find the total quantity of products associated with the orders in the "Cancelled" status.
SQL: SELECT sum(t2.order_quantity) FROM customer_orders AS t1 JOIN order_items AS t2 ON t1.order_id  =  t2.order_id WHERE t1.order_status  =  "Cancelled"

Question: What is the total amount of products purchased before 2018-03-17 07:13:53?
SQL: SELECT sum(t2.order_quantity) FROM customer_orders AS t1 JOIN order_items AS t2 ON t1.order_id  =  t2.order_id WHERE t1.order_date  <  '2018-03-17 07:13:53'

Question: Find the name of the customer who made an order most recently.
SQL: SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id ORDER BY t2.order_date DESC LIMIT 1

Question: What is the most frequently ordered product? Tell me the detail of the product
SQL: SELECT t2.product_details FROM order_items AS t1 JOIN products AS t2 ON t1.product_id  =  t2.product_id GROUP BY t1.product_id ORDER BY count(*) DESC LIMIT 1

Question: What are the name and ID of the product bought the most.
SQL: SELECT t2.product_details ,  t2.product_id FROM order_items AS t1 JOIN products AS t2 ON t1.product_id  =  t2.product_id GROUP BY t1.product_id ORDER BY sum(t1.order_quantity) LIMIT 1

Question: What are all the addresses in East Julianaside, Texas or in Gleasonmouth, Arizona.
SQL: SELECT address_content FROM addresses WHERE city  =  "East Julianaside" AND state_province_county  =  "Texas" UNION SELECT address_content FROM addresses WHERE city  =  "Gleasonmouth" AND state_province_county  =  "Arizona"

Question: What is the name of customers who do not use Cash as payment method.
SQL: SELECT customer_name FROM customers WHERE payment_method ! =  'Cash'