Task: Text to Code
Input (English): Step 1: For each row in Things table, find corresponding rows in Customer_Events table and in Timed_Status_of_Things table.
Step 2: find without repetition resident_id, service_type_code of the results of step 1 whose Status_of_Thing_Code equals Close or Date_and_Date less than 2017-06-19 02:59:21
Output (English): SELECT DISTINCT T2.resident_id , T1.service_type_code FROM Things AS T1 JOIN Customer_Events AS T2 ON T1.thing_id = T2.thing_id JOIN Timed_Status_of_Things AS T3 ON T1.thing_id = T3.thing_id WHERE T3.Status_of_Thing_Code = "Close" OR T3.Date_and_Date < "2017-06-19 02:59:21"