【发布时间】:2018-02-26 12:11:11
【问题描述】:
我有以下示例数据
MasterRecordId, MasterRecordDate, TargetDate, MasterRecordIdCount
1 | 15/02/2017 |02/02/2017 | 3
1 | 15/02/2017 |05/08/2017 | 3
1 | 15/02/2017 |12/12/2017 | 3
2 | 12/05/2017 |07/08/2017 | 2
2 | 12/05/2017 |10/08/2017 | 2
当我进行选择查询时,我希望输出如下所示
MasterRecordId, MasterRecordDate, TargetDate, MasterRecordIdCount
1 | 15/02/2017 |02/02/2017 | 3
1 | |05/08/2017 |
1 | |12/12/2017 |
2 | |07/08/2017 | 2
2 | 12/05/2017 |10/08/2017 |
基本上,MasterRecordDate 和 MasterRecordIdCount 的 MasterRecordId1 将始终相同,所以我不想重复。
【问题讨论】:
-
"12/05/2017" 的 MasterRecordId = 2 应该是第一条记录
-
您确定要这样做吗?无论如何它都会返回空值的列
-
这可以用
LAG完成,但正如其他人所说:不要在SQL中这样做;在您的应用或网页中执行此操作。
标签: sql tsql sql-server-2014