MatchDate ColA ColB PossibleDate
01/01/2012 ABC 123 01/01/2012
01/01/2012 ABC 123 09/01/2012
01/01/2012 ABC 123 01/15/2013
09/01/2012 ABC 123 01/01/2012
09/01/2012 ABC 123 09/01/2012
09/01/2012 ABC 123 09/13/2012
09/01/2012 ABC 123 10/11/2012
09/01/2012 ABC 123 01/15/2013
01/15/2013 ABC 123 01/01/2012
01/15/2013 ABC 123 09/01/2012
01/15/2013 ABC 123 01/15/2013
01/15/2013 ABC 123 02/22/2013
08/15/2012 XYZ 777 08/15/2012
08/15/2012 XYZ 777 08/28/2012
08/15/2012 XYZ 777 10/11/2012
08/15/2012 XYZ 777 01/15/2013
01/15/2013 XYZ 777 01/15/2013
01/15/2013 XYZ 777 08/15/2012
我正在寻找的结果:
MatchDate ColA ColB PossibleDate
01/01/2012 ABC 123 NULL
09/01/2012 ABC 123 09/13/2012
09/01/2012 ABC 123 10/11/2012
01/15/2013 ABC 123 02/22/2013
08/15/2012 XYZ 777 08/28/2012
08/15/2012 XYZ 777 10/11/2012
01/15/2013 XYZ 777 NULL
它应该为每个唯一的“MatchDate、ColA 和 ColB”列以及介于 MatchDate 和 PossibleDate 之间的任何“可能日期”返回行。
我添加了注释来解释为什么每列有效以及为什么无效:
MatchDate ColA ColB PossibleDate (Notes)
01/01/2012 ABC 123 01/01/2012 (Not valid as it's MatchDate already exists for "ABC, 123")
01/01/2012 ABC 123 09/01/2012 (Not valid as it's MatchDate already exists for "ABC, 123")
01/01/2012 ABC 123 01/15/2013 (Not valid as it's MatchDate already exists for "ABC, 123")
09/01/2012 ABC 123 01/01/2012 (Not valid as it's MatchDate already exists for "ABC, 123")
09/01/2012 ABC 123 09/01/2012 (Not valid as it's MatchDate already exists for "ABC, 123")
09/01/2012 ABC 123 09/13/2012 (VALID as it's PossibleDate is NOT a MatchDate and it's between 09/01/2012 and the next possible MatchDate of 01/15/2013 for "ABC, 123")
09/01/2012 ABC 123 10/11/2012 (VALID as it's PossibleDate is NOT a MatchDate and it's between 09/01/2012 and the next possible MatchDate of 01/15/2013 for "ABC, 123")
09/01/2012 ABC 123 01/15/2013 (Not valid as it's MatchDate already exists for "ABC, 123")
01/15/2013 ABC 123 01/01/2012 (Not valid as it's MatchDate already exists for "ABC, 123")
01/15/2013 ABC 123 09/01/2012 (Not valid as it's MatchDate already exists for "ABC, 123")
01/15/2013 ABC 123 01/15/2013 (Not valid as it's MatchDate already exists for "ABC, 123")
01/15/2013 ABC 123 02/22/2013 (VALID as it's PossibleDate is NOT a MatchDate and it's between 01/15/2013 and the next possible MatchDate, which doesn't exist as it's the largest MatchDate for "ABC, 123")
08/15/2012 XYZ 777 08/15/2012 (Not valid as it's MatchDate already exists for "XYZ, 777")
08/15/2012 XYZ 777 08/28/2012 (VALID as it's PossibleDate is NOT a MatchDate and it's between 08/15/2012 and the next possible MatchDate of 01/15/2013 for "XYZ, 777")
08/15/2012 XYZ 777 10/11/2012 (VALID as it's PossibleDate is NOT a MatchDate and it's between 08/15/2012 and the next possible MatchDate of 01/15/2013 for "XYZ, 777")
08/15/2012 XYZ 777 01/15/2013 (Not valid as it's MatchDate already exists for "XYZ, 777")
01/15/2013 XYZ 777 01/15/2013 (Not valid as it's MatchDate already exists for "XYZ, 777")
01/15/2013 XYZ 777 08/15/2012 (VALID as it's PossibleDate is NOT a MatchDate and it's between 01/15/2013 and the next possible MatchDate, which doesn't exist as it's the largest MatchDate for "XYZ, 777")
在此先感谢...希望它不会太混乱。