Good afternoon, i want to ask about MySql query.
I have the initial data as pict below.
I want to calculate the number of hours difference by displaying several data columns with the MySql query below.
SELECT id AS id,beacon_name AS Name,MIN(received_date) as tap_in,MAX(received_date) as tap_out,TIMESTAMPDIFF(HOUR,MIN(received_date),MAX(received_date)) AS work_hours from tb_gate_log where date(received_date) ='2023-06-06' group by id;
and it works like pict below.
however, there are cases such as there is only one data with status only "OUT" or "IN" for one id. I want the result like pict below when have status "Out" or "IN" only in one id.

how i do the query with result i wanted?
thank you,
regards.


LEFT JOINfrom that table to your table. You may also need aCOALESCEto turnNULLinto0.