I have a MySQL table having "datetime" columns begintime and endtime:
+---------------------+---------------------+
| begintime | endtime |
+---------------------+---------------------+
| 2024-05-22 10:13:23 | 2024-05-31 13:37:34 |
| 2024-05-30 17:03:21 | 2024-05-31 16:01:25 |
| 2024-05-30 17:03:21 | 2024-05-31 16:01:25 |
| 2024-05-30 17:03:21 | 2024-05-31 16:01:25 |
| 2024-05-31 15:00:00 | 2024-05-31 15:00:03 |
| 2024-05-31 15:01:32 | 2024-05-31 16:01:26 |
+---------------------+---------------------+
This table contains the rows where begintime is the same as in some row and endtime is less than in that row. For example:
| 2024-05-22 10:13:23 | 2024-05-31 12:02:18 |
Here begintime is the same as in the first row and endtime is less than in that row.
How can I filter these rows out of the table using MySQL or maybe Python’s pandas?
>Solution :
The easiest way would be to GROUP BY the begintime and getting the maximum endtime:
SELECT begintime, MAX(endtime) AS endtime
FROM your_table
GROUP BY begintime