human
Schema:
Customers (Customer_ID, Customer_name)
Services (Service_ID, Service_name)
Available_Policies (Policy_ID, policy_type_code, Customer_Phone)
Customers_Policies (Customer_ID, Policy_ID, Date_Opened, Date_Closed)
First_Notification_of_Loss (FNOL_ID, Customer_ID, Policy_ID, Service_ID)
Claims (Claim_ID, FNOL_ID, Effective_Date)
Settlements (Settlement_ID, Claim_ID, Effective_Date, Settlement_Amount)
Please answer with SQL.
assistant
Sure, I understand.
human
Retrieve the open and close dates of all the policies associated with the customer whose name contains 'Diana'
assistant
SELECT t2.date_opened , t2.date_closed FROM customers AS t1 JOIN customers_policies AS t2 ON t1.customer_id = t2.customer_id WHERE t1.customer_name LIKE '%Diana%'
human
Find all the phone numbers.
assistant
SELECT customer_phone FROM available_policies
human
Find the policy type used by more than 4 customers.
assistant
SELECT policy_type_code FROM available_policies GROUP BY policy_type_code HAVING count(*) > 4
human
What is the effective date of the claim that has the largest amount of total settlement?
assistant
SELECT t1.Effective_Date FROM claims AS t1 JOIN settlements AS t2 ON t1.claim_id = t2.claim_id GROUP BY t1.claim_id ORDER BY sum(t2.settlement_amount) DESC LIMIT 1
human
What are the maximum and minimum settlement amount on record?
assistant
SELECT max(settlement_amount) , min(settlement_amount) FROM settlements
human
Return the sum and average of all settlement amounts.
assistant
SELECT SUM( settlement_amount ) , avg ( settlement_amount ) FROM settlements ;