human
Schema:
Staff (staff_id, gender, first_name, last_name, email_address, phone_number)
Customers (customer_id, customer_type_code, address_line_1, address_line_2, town_city, state, email_address, phone_number)
Products (product_id, parent_product_id, product_category_code, date_product_first_available, date_product_discontinued, product_name, product_description, product_price)
Complaints (complaint_id, product_id, customer_id, complaint_outcome_code, complaint_status_code, complaint_type_code, date_complaint_raised, date_complaint_closed, staff_id)
Please answer with SQL.
assistant
Sure, I understand.
human
What is first names of the top 5 staff who have handled the greatest number of complaints?
assistant
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
human
Find the emails and phone numbers of all the customers, ordered by email address and phone number.
assistant
SELECT email_address , phone_number FROM customers ORDER BY email_address , phone_number
human
What is the phone number of the customer who has filed the most recent complaint?
assistant
SELECT t1.phone_number FROM customers AS t1 JOIN complaints AS t2 ON t1.customer_id = t2.customer_id ORDER BY t2.date_complaint_raised DESC LIMIT 1
human
How many customers are there in the customer type with the most customers?
assistant
SELECT count(*) FROM customers GROUP BY customer_type_code ORDER BY count(*) DESC LIMIT 1
human
How many customers are there?
assistant
SELECT count(*) FROM customers
human
What are the phone numbers of all customers and all staff members?
assistant
SELECT phone_number FROM customers UNION SELECT phone_number FROM staff ;