[Schema (values) (types)]: | local_govt_and_lot |  Customers : customer_id (text) , customer_details (number) | Properties : property_id (text) , property_type_code (number) , property_address (text) , other_details (number) | Residents : resident_id (text) , property_id (number) , date_moved_in (text) , date_moved_out (number) , other_details (text) | Organizations : organization_id (text) , parent_organization_id (number) , organization_details (text) | Services : service_id (text) , organization_id (number) , service_type_code (text) , service_details (number) | Residents_Services : resident_id (text) , service_id (number) , date_moved_in (text) , property_id (number) , date_requested (text) , date_provided (text) , other_details (text) | Things : thing_id (text) , organization_id (number) , type_of_thing_code (text) , service_type_code (number) , service_details (text) | Customer_Events : customer_event_id (text) , customer_id (number) , date_moved_in (text) , property_id (number) , resident_id (text) , thing_id (text) | Customer_Event_Notes : customer_event_note_id (text) , customer_event_id (number) , service_type_code (text) , resident_id (number) , property_id (text) , date_moved_in (text) | Timed_Status_of_Things : thing_id (text) , date_and_date (number) , status_of_thing_code (text) | Timed_Locations_of_Things : thing_id (text) , date_and_time (number) , location_code (text);
[Primary Keys]: customers : customer_id, properties : property_id, residents : resident_id, organizations : organization_id, services : service_id, residents_services : resident_id, things : thing_id, customer_events : customer_event_id, customer_event_notes : customer_event_note_id, timed_status_of_things : thing_id, timed_locations_of_things : thing_id
[Foreign Keys]: residents : property_id = properties : property_id | services : organization_id = organizations : organization_id | residents_services : resident_id = residents : resident_id | residents_services : property_id = residents : property_id | residents_services : date_moved_in = residents : date_moved_in | residents_services : service_id = services : service_id | things : organization_id = organizations : organization_id | customer_events : resident_id = residents : resident_id | customer_events : property_id = residents : property_id | customer_events : date_moved_in = residents : date_moved_in | customer_events : customer_id = customers : customer_id | customer_events : thing_id = things : thing_id | customer_event_notes : customer_event_id = customer_events : customer_event_id | timed_status_of_things : thing_id = things : thing_id | timed_locations_of_things : thing_id = things : thing_id

Question: How many residents does each property have? List property id and resident count.
SQL: SELECT T1.property_id ,  count(*) FROM properties AS T1 JOIN residents AS T2 ON T1.property_id  =  T2.property_id GROUP BY T1.property_id

Question: What is the distinct service types that are provided by the organization which has detail 'Denesik and Sons Party'?
SQL: SELECT DISTINCT T1.service_type_code FROM services AS T1 JOIN organizations AS T2 ON T1.organization_id  =  T2.organization_id WHERE T2.organization_details  =  'Denesik and Sons Party'

Question: How many services has each resident requested? List the resident id, details, and the count in descending order of the count.
SQL: SELECT T1.resident_id ,  T1.other_details ,  count(*) FROM Residents AS T1 JOIN Residents_Services AS T2 ON T1.resident_id  =  T2.resident_id GROUP BY T1.resident_id ORDER BY count(*) DESC

Question: What is the maximum number that a certain service is provided? List the service id, details and number.
SQL: SELECT T1.service_id ,  T1.service_details ,  count(*) FROM Services AS T1 JOIN Residents_Services AS T2 ON T1.service_id  =  T2.service_id GROUP BY T1.service_id ORDER BY count(*) DESC LIMIT 1

Question: List the id and type of each thing, and the details of the organization that owns it.
SQL: SELECT T1.thing_id ,  T1.type_of_Thing_Code ,  T2.organization_details FROM Things AS T1 JOIN Organizations AS T2 ON T1.organization_id  =  T2.organization_id

Question: What are the id and details of the customers who have at least 3 events?
SQL: SELECT T1.customer_id ,  T1.customer_details FROM Customers AS T1 JOIN Customer_Events AS T2 ON T1.customer_id  =  T2.customer_id GROUP BY T1.customer_id HAVING count(*)  >=  3

Question: What is each customer's move in date, and the corresponding customer id and details?
SQL: SELECT T2.date_moved_in ,  T1.customer_id ,  T1.customer_details FROM Customers AS T1 JOIN Customer_Events AS T2 ON T1.customer_id  =  T2.customer_id

Question: Which events have the number of notes between one and three? List the event id and the property id.
SQL: SELECT T1.Customer_Event_ID  ,  T1.property_id FROM Customer_Events AS T1 JOIN Customer_Event_Notes AS T2 ON T1.Customer_Event_ID  =  T2.Customer_Event_ID GROUP BY T1.customer_event_id HAVING count(*) BETWEEN 1 AND 3

Question: What are the distinct id and type of the thing that has the status 'Close' or has a status record before the date '2017-06-19 02:59:21'
SQL: SELECT DISTINCT T2.thing_id ,  T2.Type_of_Thing_Code FROM Timed_Status_of_Things AS T1 JOIN Things AS T2 ON T1.thing_id  =  T2.thing_id WHERE T1.Status_of_Thing_Code  =  'Close' OR T1.Date_and_Date  <  '2017-06-19 02:59:21'

Question: How many distinct locations have the things with service detail 'Unsatisfied' been located in?
SQL: SELECT count(DISTINCT T2.Location_Code) FROM Things AS T1 JOIN Timed_Locations_of_Things AS T2 ON T1.thing_id  =  T2.thing_id WHERE T1.service_details  =  'Unsatisfied'

Question: How many different status codes of things are there?
SQL: SELECT count(DISTINCT Status_of_Thing_Code) FROM Timed_Status_of_Things

Question: Which organizations are not a parent organization of others? List the organization id.
SQL: SELECT organization_id FROM organizations EXCEPT SELECT parent_organization_id FROM organizations

Question: When is the last day any resident moved in?
SQL: SELECT max(date_moved_in) FROM Residents

Question: What are the resident details containing the substring 'Miss'?
SQL: SELECT other_details FROM Residents WHERE other_details LIKE '%Miss%'

Question: List the customer event id and the corresponding move in date and property id.
SQL: SELECT customer_event_id ,  date_moved_in ,  property_id FROM customer_events

Question: How many customers did not have any event?
SQL: SELECT count(*) FROM customers WHERE customer_id NOT IN ( SELECT customer_id FROM customer_events )

Question: What are the distinct move in dates of the residents?
SQL: SELECT DISTINCT date_moved_in FROM residents