简体   繁体   中英

Get MIN and MAX values from group of Dates

I have a table like this:

|date_start|time_start|time_end|
|2020-06-01|08:36     |12:34   |
|2020-06-01|12:40     |14:36   |
|2020-06-01|16:45     |20:00   |
|2020-06-02|09:36     |12:34   |
|2020-06-02|15:36     |19:44   |
|2020-06-03|12:36     |14:54   |
|2020-06-03|18:36     |23:04   |

I need a query to return the MIN(time_start) and MAX(time_end) from each date so for above table the result must be

DATE         MIN  MAX
2020-06-01 08:36 20:00
2020-06-02 09:36 19:44
2020-06-03 12:36 23:04

I tried with subqueries but not succeeded to have a result.

Try this:

SELECT date_start as DATE, MAX(time_start), MIN(time_end)
FROM
date_table
GROUP BY date_start;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM