我如何从同一个表的两个重叠日期行中为相同的 id 获取一行。我有超过 50000 条记录。
我有以下示例数据。
ID start_dt end_dt division
1212 04/01/2006 03/01/2007 second
1212 05/01/2009 01/01/2010 second
1212 04/01/2006 03/01/2008 second --- This should be selected as longest timeframe
1212 09/03/2007 03/01/2008 third
1213 05/03/2005 04/11/2009 second
1214 07/03/2007 03/01/2008 third
我应该得到的数据如下。
ID start_dt end_dt division
1212 04/01/2006 03/01/2008 second
1212 05/01/2009 01/01/2010 second
1213 05/03/2005 04/11/2009 second
1214 07/03/2007 03/01/2008 third
谢谢你。拉姆