Database: department_store

Question: What are the highest and lowest prices of products, grouped by and alphabetically ordered by product type?
SQL: SELECT max(product_price) ,  min(product_price) ,  product_type_code FROM products GROUP BY product_type_code ORDER BY product_type_code

Question: List the order id, customer id for orders in Cancelled status, ordered by their order dates.
SQL: SELECT order_id ,  customer_id FROM customer_orders WHERE order_status_code  =   "Cancelled" ORDER BY order_date

Question: Find the names of products that were bought by at least two distinct customers.
SQL: SELECT DISTINCT T3.product_name FROM customer_orders AS T1 JOIN order_items AS T2 ON T1.order_id  =  T2.order_id JOIN products AS T3 ON T2.product_id  =  T3.product_id GROUP BY T3.product_id HAVING COUNT (DISTINCT T1.customer_id)  >=  2

Question: Find the names of customers who have bought at least three distinct products.
SQL: SELECT DISTINCT T1.customer_name 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 GROUP BY T1.customer_id HAVING COUNT (DISTINCT T3.product_id)  >=  3

Question: Find the name and gender of the staff who has been assigned the job of Sales Person but never Clerical Staff.
SQL: SELECT T1.staff_name ,  T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id  =  T2.staff_id WHERE T2.job_title_code  =  "Sales Person" EXCEPT SELECT T1.staff_name ,  T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id  =  T2.staff_id WHERE T2.job_title_code  =  "Clerical Staff"

Question: Find the id and name of customers whose address contains WY state and do not use credit card for payment.
SQL: SELECT customer_id ,  customer_name FROM customers WHERE customer_address LIKE "%WY%" AND payment_method_code != "Credit Card"

Question: Find the average price of all product clothes.
SQL: SELECT avg(product_price) FROM products WHERE product_type_code  =  'Clothes'