CREATE TABLE Problem_Category_Codes (
    problem_category_code TEXT PRIMARY KEY,
    problem_category_description TEXT
);
CREATE TABLE Problem_Log (
    problem_log_id NUMBER PRIMARY KEY,
    assigned_to_staff_id NUMBER,
    problem_id NUMBER,
    problem_category_code TEXT,
    problem_status_code TEXT,
    log_entry_date TIME,
    log_entry_description TEXT,
    log_entry_fix TEXT,
    other_log_details TEXT,
    FOREIGN KEY ("problem_status_code") REFERENCES Problem_Status_Codes("problem_status_code"),
    FOREIGN KEY ("problem_id") REFERENCES Problems("problem_id"),
    FOREIGN KEY ("assigned_to_staff_id") REFERENCES Staff("staff_id"),
    FOREIGN KEY ("problem_category_code") REFERENCES Problem_Category_Codes("problem_category_code")
);
CREATE TABLE Problem_Status_Codes (
    problem_status_code TEXT PRIMARY KEY,
    problem_status_description TEXT
);
CREATE TABLE Product (
    product_id NUMBER PRIMARY KEY,
    product_name TEXT,
    product_details TEXT
);
CREATE TABLE Staff (
    staff_id NUMBER PRIMARY KEY,
    staff_first_name TEXT,
    staff_last_name TEXT,
    other_staff_details TEXT
);
CREATE TABLE Problems (
    problem_id NUMBER PRIMARY KEY,
    product_id NUMBER,
    closure_authorised_by_staff_id NUMBER,
    reported_by_staff_id NUMBER,
    date_problem_reported TIME,
    date_problem_closed TIME,
    problem_description TEXT,
    other_problem_details TEXT,
    FOREIGN KEY ("reported_by_staff_id") REFERENCES Staff("staff_id"),
    FOREIGN KEY ("product_id") REFERENCES Product("product_id"),
    FOREIGN KEY ("closure_authorised_by_staff_id") REFERENCES Staff("staff_id")
);

Question: Sort all the distinct product names in alphabetical order.
SQL: SELECT DISTINCT product_name FROM product ORDER BY product_name

Question: List all the distinct product names ordered by product id?
SQL: SELECT DISTINCT product_name FROM product ORDER BY product_id

Question: What is the list of distinct product names sorted by product id?
SQL: SELECT DISTINCT product_name FROM product ORDER BY product_id

Question: What are the id of problems reported by the staff named Dameon Frami or Jolie Weber?
SQL: SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Dameon" AND T2.staff_last_name = "Frami" UNION SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Jolie" AND T2.staff_last_name = "Weber"

Question: Which problems were reported by the staff named Dameon Frami or Jolie Weber? Give me the ids of the problems.
SQL: SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Dameon" AND T2.staff_last_name = "Frami" UNION SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Jolie" AND T2.staff_last_name = "Weber"

Question: What are the product ids for the problems reported by Christop Berge with closure authorised by Ashley Medhurst?
SQL: SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Christop" AND T2.staff_last_name = "Berge" INTERSECT SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.closure_authorised_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Ashley" AND T2.staff_last_name = "Medhurst"

Question: For which product was there a problem reported by Christop Berge, with closure authorised by Ashley Medhurst? Return the product ids.
SQL: SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Christop" AND T2.staff_last_name = "Berge" INTERSECT SELECT product_id FROM problems AS T1 JOIN staff AS T2 ON T1.closure_authorised_by_staff_id = T2.staff_id WHERE T2.staff_first_name = "Ashley" AND T2.staff_last_name = "Medhurst"

Question: What are the ids of the problems reported before the date of any problem reported by Lysanne Turcotte?
SQL: SELECT T1.problem_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE date_problem_reported  <  ( SELECT min(date_problem_reported) FROM problems AS T3 JOIN staff AS T4 ON T3.reported_by_staff_id = T4.staff_id WHERE T4.staff_first_name = "Lysanne" AND T4.staff_last_name = "Turcotte" )

Question: Which problems were reported before the date of any problem reported by the staff Lysanne Turcotte? Give me the ids of the problems.
SQL: SELECT T1.problem_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE date_problem_reported  <  ( SELECT min(date_problem_reported) FROM problems AS T3 JOIN staff AS T4 ON T3.reported_by_staff_id = T4.staff_id WHERE T4.staff_first_name = "Lysanne" AND T4.staff_last_name = "Turcotte" )

Question: What are the ids of the problems reported after the date of any problems reported by Rylan Homenick?
SQL: SELECT T1.problem_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE date_problem_reported  >  ( SELECT max(date_problem_reported) FROM problems AS T3 JOIN staff AS T4 ON T3.reported_by_staff_id = T4.staff_id WHERE T4.staff_first_name = "Rylan" AND T4.staff_last_name = "Homenick" )

Question: Find the ids of the problems reported after the date of any problems reported by the staff Rylan Homenick.
SQL: SELECT T1.problem_id FROM problems AS T1 JOIN staff AS T2 ON T1.reported_by_staff_id = T2.staff_id WHERE date_problem_reported  >  ( SELECT max(date_problem_reported) FROM problems AS T3 JOIN staff AS T4 ON T3.reported_by_staff_id = T4.staff_id WHERE T4.staff_first_name = "Rylan" AND T4.staff_last_name = "Homenick" )

Question: Find the top 3 products which have the largest number of problems?
SQL: SELECT T2.product_name FROM problems AS T1 JOIN product AS T2 ON T1.product_id = T2.product_id GROUP BY T2.product_name ORDER BY count(*) DESC LIMIT 3

Question: What are the three products that have the most problems?s
SQL: SELECT T2.product_name FROM problems AS T1 JOIN product AS T2 ON T1.product_id = T2.product_id GROUP BY T2.product_name ORDER BY count(*) DESC LIMIT 3

Question: List the ids of the problems from the product "voluptatem" that are reported after 1995?
SQL: SELECT T1.problem_id FROM problems AS T1 JOIN product AS T2 ON T1.product_id = T2.product_id WHERE T2.product_name = "voluptatem" AND T1.date_problem_reported > "1995"

Question: What are the ids of the problems that are from the product "voluptatem" and are reported after 1995?
SQL: SELECT T1.problem_id FROM problems AS T1 JOIN product AS T2 ON T1.product_id = T2.product_id WHERE T2.product_name = "voluptatem" AND T1.date_problem_reported > "1995"

Question: Find the first and last name of the staff members who reported problems from the product "rem" but not "aut"?
SQL: SELECT T3.staff_first_name ,  T3.staff_last_name FROM problems AS T1 JOIN product AS T2 JOIN staff AS T3 ON T1.product_id = T2.product_id AND T1.reported_by_staff_id = T3.staff_id WHERE T2.product_name = "rem" EXCEPT SELECT T3.staff_first_name ,  T3.staff_last_name FROM problems AS T1 JOIN product AS T2 JOIN staff AS T3 ON T1.product_id = T2.product_id AND T1.reported_by_staff_id = T3.staff_id WHERE T2.product_name = "aut"

Question: Which staff members who reported problems from the product "rem" but not "aut"? Give me their first and last names.
SQL: SELECT T3.staff_first_name ,  T3.staff_last_name FROM problems AS T1 JOIN product AS T2 JOIN staff AS T3 ON T1.product_id = T2.product_id AND T1.reported_by_staff_id = T3.staff_id WHERE T2.product_name = "rem" EXCEPT SELECT T3.staff_first_name ,  T3.staff_last_name FROM problems AS T1 JOIN product AS T2 JOIN staff AS T3 ON T1.product_id = T2.product_id AND T1.reported_by_staff_id = T3.staff_id WHERE T2.product_name = "aut"