What is the earliest status record date?
select min(date_and_date) from timed_status_of_things
Which things have a status record before the date '2017-06-19 02:59:21'?
select * from timed_status_of_things where date_and_date < '2017-06-19 02:59:21'
Also show the things that have the status 'Close'.
select * from timed_status_of_things where status_of_thing_code = 'Close' or date_and_date < '2017-06-19 02:59:21'
Show the distinct ids and also the type of thing.
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'