假设你有一个支持窗口函数的DBMS,你可以做到这一点。
select category, grp, min(date) as min_date, max(date) as max_date
from (
select category, date
, row_number() over (order by date)
- row_number() over (partition by category order by date) as grp
from T
) as X