CREATE TABLE Addresses (
    address_id NUMBER PRIMARY KEY,
    address_details TEXT
);
CREATE TABLE Staff (
    staff_id NUMBER PRIMARY KEY,
    staff_gender TEXT,
    staff_name TEXT
);
CREATE TABLE Suppliers (
    supplier_id NUMBER PRIMARY KEY,
    supplier_name TEXT,
    supplier_phone TEXT
);
CREATE TABLE Department_Store_Chain (
    dept_store_chain_id NUMBER PRIMARY KEY,
    dept_store_chain_name TEXT
);
CREATE TABLE Customers (
    customer_id NUMBER PRIMARY KEY,
    payment_method_code TEXT,
    customer_code TEXT,
    customer_name TEXT,
    customer_address TEXT,
    customer_phone TEXT,
    customer_email TEXT
);
CREATE TABLE Products (
    product_id NUMBER PRIMARY KEY,
    product_type_code TEXT,
    product_name TEXT,
    product_price NUMBER
);
CREATE TABLE Supplier_Addresses (
    supplier_id NUMBER PRIMARY KEY,
    address_id NUMBER,
    date_from TIME,
    date_to TIME,
    FOREIGN KEY ("supplier_id") REFERENCES Suppliers("supplier_id"),
    FOREIGN KEY ("address_id") REFERENCES Addresses("address_id")
);
CREATE TABLE Customer_Addresses (
    customer_id NUMBER PRIMARY KEY,
    address_id NUMBER,
    date_from TIME,
    date_to TIME,
    FOREIGN KEY ("customer_id") REFERENCES Customers("customer_id"),
    FOREIGN KEY ("address_id") REFERENCES Addresses("address_id")
);
CREATE TABLE Customer_Orders (
    order_id NUMBER PRIMARY KEY,
    customer_id NUMBER,
    order_status_code TEXT,
    order_date TIME,
    FOREIGN KEY ("customer_id") REFERENCES Customers("customer_id")
);
CREATE TABLE Department_Stores (
    dept_store_id NUMBER PRIMARY KEY,
    dept_store_chain_id NUMBER,
    store_name TEXT,
    store_address TEXT,
    store_phone TEXT,
    store_email TEXT,
    FOREIGN KEY ("dept_store_chain_id") REFERENCES Department_Store_Chain("dept_store_chain_id")
);
CREATE TABLE Departments (
    department_id NUMBER PRIMARY KEY,
    dept_store_id NUMBER,
    department_name TEXT,
    FOREIGN KEY ("dept_store_id") REFERENCES Department_Stores("dept_store_id")
);
CREATE TABLE Order_Items (
    order_item_id NUMBER PRIMARY KEY,
    order_id NUMBER,
    product_id NUMBER,
    FOREIGN KEY ("product_id") REFERENCES Products("product_id"),
    FOREIGN KEY ("order_id") REFERENCES Customer_Orders("order_id")
);
CREATE TABLE Product_Suppliers (
    product_id NUMBER PRIMARY KEY,
    supplier_id NUMBER,
    date_supplied_from TIME,
    date_supplied_to TIME,
    total_amount_purchased TEXT,
    total_value_purchased NUMBER,
    FOREIGN KEY ("product_id") REFERENCES Products("product_id"),
    FOREIGN KEY ("supplier_id") REFERENCES Suppliers("supplier_id")
);
CREATE TABLE Staff_Department_Assignments (
    staff_id NUMBER PRIMARY KEY,
    department_id NUMBER,
    date_assigned_from TIME,
    job_title_code TEXT,
    date_assigned_to TIME,
    FOREIGN KEY ("staff_id") REFERENCES Staff("staff_id"),
    FOREIGN KEY ("department_id") REFERENCES Departments("department_id")
);

Question: Find the names of customers who have bought by 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: What are the distinct names of customers who have purchased at least three different 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: What are the names and genders of staff who have held the title 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: What are the ids and names of customers with addressed that contain WY and who do not use a 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'

Question: What is the average price of clothes?
SQL: SELECT avg(product_price) FROM products WHERE product_type_code  =  'Clothes'

Question: Find the name of the most expensive hardware product.
SQL: SELECT product_name FROM products WHERE product_type_code  =  'Hardware' ORDER BY product_price DESC LIMIT 1

Question: What is the name of the hardware product with the greatest price?
SQL: SELECT product_name FROM products WHERE product_type_code  =  'Hardware' ORDER BY product_price DESC LIMIT 1