CREATE TABLE Staff (
    staff_id NUMBER PRIMARY KEY,
    gender TEXT,
    first_name TEXT,
    last_name TEXT,
    email_address TEXT,
    phone_number TEXT
);
CREATE TABLE Customers (
    customer_id NUMBER PRIMARY KEY,
    customer_type_code TEXT,
    address_line_1 TEXT,
    address_line_2 TEXT,
    town_city TEXT,
    state TEXT,
    email_address TEXT,
    phone_number TEXT
);
CREATE TABLE Products (
    product_id NUMBER PRIMARY KEY,
    parent_product_id NUMBER,
    product_category_code TEXT,
    date_product_first_available TIME,
    date_product_discontinued TIME,
    product_name TEXT,
    product_description TEXT,
    product_price NUMBER
);
CREATE TABLE Complaints (
    complaint_id NUMBER,
    product_id NUMBER,
    customer_id NUMBER,
    complaint_outcome_code TEXT,
    complaint_status_code TEXT,
    complaint_type_code TEXT,
    date_complaint_raised TIME,
    date_complaint_closed TIME,
    staff_id NUMBER,
    FOREIGN KEY ("customer_id") REFERENCES Customers("customer_id"),
    FOREIGN KEY ("product_id") REFERENCES Products("product_id"),
    FOREIGN KEY ("staff_id") REFERENCES Staff("staff_id")
);

Question: Count the number of customers that have the customer type that is most common.
SQL: SELECT count(*) FROM customers GROUP BY customer_type_code ORDER BY count(*) DESC LIMIT 1

Question: What is the last name of the staff who has handled the first ever complaint?
SQL: SELECT t1.last_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id  =  t2.staff_id ORDER BY t2.date_complaint_raised LIMIT 1

Question: Return the last name of the staff member who handled the complaint with the earliest date raised.
SQL: SELECT t1.last_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id  =  t2.staff_id ORDER BY t2.date_complaint_raised LIMIT 1

Question: How many distinct complaint type codes are there in the database?
SQL: SELECT count(DISTINCT complaint_type_code) FROM complaints

Question: Count the number of different complaint type codes.
SQL: SELECT count(DISTINCT complaint_type_code) FROM complaints

Question: Find the address line 1 and 2 of the customer with email "vbogisich@example.org".
SQL: SELECT address_line_1 ,  address_line_2 FROM customers WHERE email_address  =  "vbogisich@example.org"

Question: What are lines 1 and 2 of the addressed of the customer with the email "vbogisich@example.org"?
SQL: SELECT address_line_1 ,  address_line_2 FROM customers WHERE email_address  =  "vbogisich@example.org"

Question: Find the number of complaints with Product Failure type for each complaint status.
SQL: SELECT complaint_status_code ,  count(*) FROM complaints WHERE complaint_type_code  =  "Product Failure" GROUP BY complaint_status_code

Question: Of complaints with the type code "Product Failure", how many had each different status code?
SQL: SELECT complaint_status_code ,  count(*) FROM complaints WHERE complaint_type_code  =  "Product Failure" GROUP BY complaint_status_code

Question: What is first names of the top 5 staff who have handled the greatest number of complaints?
SQL: SELECT t1.first_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id  =  t2.staff_id GROUP BY t2.staff_id ORDER BY count(*) LIMIT 5

Question: Return the first names of the 5 staff members who have handled the most complaints.
SQL: SELECT t1.first_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id  =  t2.staff_id GROUP BY t2.staff_id ORDER BY count(*) LIMIT 5

Question: Which state has the most customers?
SQL: SELECT state FROM customers GROUP BY state ORDER BY count(*) LIMIT 1

Question: Give the state that has the most customers.
SQL: SELECT state FROM customers GROUP BY state ORDER BY count(*) LIMIT 1