-- Database schema
| Customers : customer_id [ INT ] primary_key , customer_details [ TEXT ] | Properties : property_id [ INT ] primary_key , property_type_code [ TEXT ] , property_address [ TEXT ] , other_details [ TEXT ] | Residents : resident_id [ INT ] primary_key , property_id [ INT ] Residents.property_id = Properties.property_id , date_moved_in [ TEXT ] , date_moved_out [ TEXT ] , other_details [ TEXT ] | Organizations : organization_id [ INT ] primary_key , parent_organization_id [ INT ] , organization_details [ TEXT ] | Services : service_id [ INT ] primary_key , organization_id [ INT ] Services.organization_id = Organizations.organization_id , service_type_code [ TEXT ] , service_details [ TEXT ] | Residents_Services : resident_id [ INT ] primary_key Residents_Services.resident_id = Residents.resident_id , service_id [ INT ] Residents_Services.service_id = Services.service_id , date_moved_in [ TEXT ] Residents_Services.date_moved_in = Residents.date_moved_in , property_id [ INT ] Residents_Services.property_id = Residents.property_id , date_requested [ TEXT ] , date_provided [ TEXT ] , other_details [ TEXT ] | Things : thing_id [ INT ] primary_key , organization_id [ INT ] Things.organization_id = Organizations.organization_id , Type_of_Thing_Code [ TEXT ] , service_type_code [ TEXT ] , service_details [ TEXT ] | Customer_Events : Customer_Event_ID [ INT ] primary_key , customer_id [ INT ] Customer_Events.customer_id = Customers.customer_id , date_moved_in [ TEXT ] Customer_Events.date_moved_in = Residents.date_moved_in , property_id [ INT ] Customer_Events.property_id = Residents.property_id , resident_id [ INT ] Customer_Events.resident_id = Residents.resident_id , thing_id [ INT ] Customer_Events.thing_id = Things.thing_id | Customer_Event_Notes : Customer_Event_Note_ID [ INT ] primary_key , Customer_Event_ID [ INT ] Customer_Event_Notes.Customer_Event_ID = Customer_Events.Customer_Event_ID , service_type_code [ TEXT ] , resident_id [ INT ] , property_id [ INT ] , date_moved_in [ TEXT ] | Timed_Status_of_Things : thing_id [ INT ] primary_key Timed_Status_of_Things.thing_id = Things.thing_id , Date_and_Date [ TEXT ] , Status_of_Thing_Code [ TEXT ] | Timed_Locations_of_Things : thing_id [ INT ] primary_key Timed_Locations_of_Things.thing_id = Things.thing_id , Date_and_Time [ TEXT ] , Location_Code [ TEXT ] |
-- -- 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'

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';