Database: department_store

Question: What are the names and ids of customers whose address contains TN?
SQL: SELECT customer_name ,  customer_id FROM customers WHERE customer_address LIKE "%TN%"

Question: Return the name and gender of the staff who was assigned in 2016.
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.date_assigned_from LIKE "2016%"

Question: List the name of staff who has been assigned multiple jobs.
SQL: SELECT T1.staff_name FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id  =  T2.staff_id GROUP BY T2.staff_id HAVING COUNT (*)  >  1

Question: List the name and phone number of all suppliers in the alphabetical order of their addresses.
SQL: SELECT T1.supplier_name ,  T1.supplier_phone FROM Suppliers AS T1 JOIN supplier_addresses AS T2 ON T1.supplier_id  =  T2.supplier_id JOIN addresses AS T3 ON T2.address_id  =  T3.address_id ORDER BY T3.address_details

Question: What are the phone numbers of all customers and suppliers?
SQL: SELECT customer_phone FROM customers UNION SELECT supplier_phone FROM suppliers

Question: Return the ids of all products that were ordered more than three times or supplied more than 80000.
SQL: SELECT product_id FROM Order_Items GROUP BY product_id HAVING count(*)  >  3 UNION SELECT product_id FROM Product_Suppliers GROUP BY product_id HAVING sum(total_amount_purchased)  >  80000

Question: What are id and name of the products whose price is lower than 600 or higher than 900?
SQL: SELECT product_id ,  product_name FROM products WHERE product_price  <  600 OR product_price  >  900

Question: Find the id of suppliers whose average amount purchased for each product is above 50000 or below 30000.
SQL: SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id HAVING avg(total_amount_purchased)  >  50000 OR avg(total_amount_purchased)  <  30000

Question: What are the average amount purchased and value purchased for the supplier who supplies the most products.
SQL: SELECT avg(total_amount_purchased) ,  avg(total_value_purchased) FROM Product_Suppliers WHERE supplier_id  =  (SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id ORDER BY count(*) DESC LIMIT 1)

Question: What is the largest and smallest customer codes?
SQL: SELECT max(customer_code) ,  min(customer_code) FROM Customers

Question: List the names of all the distinct customers who bought a keyboard.
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 JOIN products AS T4 ON T3.product_id  =  T4.product_id WHERE T4.product_name  =  "keyboard"

Question: List the names and phone numbers of all the distinct suppliers who supply red jeans.
SQL: SELECT DISTINCT T1.supplier_name ,  T1.supplier_phone FROM suppliers AS T1 JOIN product_suppliers AS T2 ON T1.supplier_id  =  T2.supplier_id JOIN products AS T3 ON T2.product_id  =  T3.product_id WHERE T3.product_name  =  "red jeans"