如何通过比较多个行和列来获取StartDate和EndDate

时间:2019-06-01 11:23:25

标签: sql-server

我的表中有以下数据:

ID     StartDate    EndDate 
-------------------------------
222    2019-04-01   2019-04-16
222    2019-04-16   2019-04-30
562    2019-04-01   2019-04-08
562    2019-04-08   2019-04-15
562    2019-04-15   2019-04-22
562    2019-04-22   2019-04-29
228    2019-04-02   2019-04-09
228    2019-04-10   2019-04-16
228    2019-04-15   2019-04-23
228    2019-04-26   2019-04-30
228    2019-04-01   2019-04-16

条件是如果Enddate = StartDate,则必须检查其StartDateEndDate以及预期的输出,如下所示:

ID      StartDate       EndDate 
-----------------------------------
222     2019-04-01      2019-04-30
562     2019-04-01      2019-04-29

1 个答案:

答案 0 :(得分:0)

这就是我使用#include <vector> #include <list> #include <functional> class someType {}; void func(std::list<std::function<void(std::vector<someType>&)>> (& par)(const std::vector<someType>&)) { // some input const std::vector<someType> input; // the function returns the list std::list<std::function<void(std::vector<someType>&)>> res = par(input); // we can iterate over the list for (auto & i : res) { std::vector<someType> other; // and call the functions inside i(other); } } 的方式。您可以使用LEAD来检查下一个LEAD与当前StartDate的值是否相同。如果是,我返回0,如果不是,则返回1,并假设这些值的EndDate为0,我们知道所有日期都是连续的:

SUM