My data is like this
| id. | date. | datetime. |
|:---- |:------:| -----:|
| 123 | 2022-01-02 | 2022-01-02 8:00:00 |
| 123 | 2022-01-02 | 2022-01-02 10:00:00 |
| 123 | 2022-01-03 | 2022-01-03 2:00:00 |
| 123 | 2022-01-03 | 2022-01-03 8:30:00 |
| 123 | 2022-01-03 | 2022-01-03 17:30:00 |
I want to select and order my data like this: (I want my result like this)
| id. | date. | in. | out. |
|:---- |:------:| -----:| ---:|
| 123 | 2022-01-02| 2022-01-02 8:00:00 | 2022-01-03 2:00:00|
| 123 | 2022-01-03| 2022-01-03 8:30:00 | 2022-01-03 17:30:00|
I have been using like this
SELECT
[person_id] AS 'id.'
, [date] AS 'date.'
, MIN(datetime) AS 'in.'
, MAX(datetime) AS 'out.'
FROM
tablename
GROUP BY
[person_id]
, [date]
Normal result: (I don't want result like this)
| id. | date. | in. | out. |
|:---- |:------:| -----:| ---:|
| 123 | 2022-01-02| 2022-01-02 8:00:00 | 2022-01-03 10:00:00|
| 123 | 2022-01-03| 2022-01-03 02:00:00 | 2022-01-03 17:30:00|
to get my results but failed because using max(datetime) function was select the max datetime same date only but I want to select my max datetime less than 05:00:00. Please help me.
